Commit 42edba9a authored by Trisha Gee's avatar Trisha Gee
Browse files

[Ch10b] TreeSet examples

parent 983a0e18
Loading
Loading
Loading
Loading
+20 −0
Changes for src/main/java/ch10b/Jukebox9.java: 20 added lines, 0 removed lines.
Original line number Diff line number Diff line
package ch10b;

import java.util.*;

public class Jukebox9 {
  private final MockMoreSongs mockFile = new MockMoreSongs();

  public static void main(String[] args) {
    new Jukebox9().go();
  }

  public void go() {
    List<SongV4> songList = mockFile.getSongs();
    System.out.println(songList);
    songList.sort((one, two) -> one.getTitle().compareTo(two.getTitle()));
    System.out.println(songList);
    Set<SongV4> songSet = new TreeSet<>(songList);
    System.out.println(songSet);
  }
}
+28 −0
Changes for src/main/java/ch10b/TestTree.java: 28 added lines, 0 removed lines.
Original line number Diff line number Diff line
package ch10b;

import java.util.*;

public class TestTree {
   public static void main (String[] args) {
      new TestTree().go();
   }

   public void go() {
     Book b1 = new Book("How Cats Work");
     Book b2 = new Book("Remix your Body");
     Book b3 = new Book("Finding Emo");
     
     TreeSet<Book> tree = new TreeSet<>();
     tree.add(b1);
     tree.add(b2);
     tree.add(b3);
     System.out.println(tree);
   }
}

class Book {
   String title;
   public Book(String t) {
     title = t;
   }
}
 No newline at end of file