public class Book {
String title;
public Book(String t) {
title = t;
}
}
public class Bookcomparator implements Comparator<Book> {
public int compare(Book one, Book two) {
return (one.title.compareTo(two.title));
}
}
public class TreesetTest {
public void go() {
Book b1 = new Book("How");
Book b2 = new Book("Remix");
Book b3 = new Book("Finding ");
Bookcomparator bc = new Bookcomparator();
TreeSet<Book> set = new TreeSet<Book>(bc);
set.add(b1);
set.add(b2);
set.add(b3);
System.out.println(set);
}
}
public class Test {
public static void main(String args[]) {
TreesetTest t = new TreesetTest();
t.go();
}
}
このプログラムを実行すると、次のように表示されます
[first.Book@c2ea3f, first.Book@a0dcd9, first.Book@1034bb5]
誰か助けてください。