Given the code fragments:
public class Book implements Comparator<Book> {
String name;
double price;
public Book () {}
public Book(String name, double price) {
this.name = name;
this.price = price;
}
public int compare(Book b1, Book b2) {
return b1.name.compareTo(b2.name);
}
public String toString() {
return name + ":" + price;
}
}
and
List<Book>books = Arrays.asList (
new Book ("Beginning with Java", 2),
new book ("A Guide to Java Tour", 3)
);
Collections.sort(books, new Book());
System.out.print(books);
What is the result?
Innovation
Highly Voted 5 years, 5 months agoSvetleto13
Highly Voted 4 years, 2 months agoSvetleto13
4 years, 1 month agoalboy68
Most Recent 11 months, 1 week agoasdfjhfgjuaDCV
1 year, 4 months agosteefaand
1 year, 5 months agor1muka5
2 years, 4 months agoayzo
4 years, 5 months agopul26
4 years, 7 months ago