I have an ArrayList with 3 Objects in it. Each Object is a new book in my case. Each book has different values for the title, retail price, quantity in stock, etc.
How do I compare and sort the retail price for all of the objects. I have heard of
Collections.sort(books, new Comparator<BookInfo>(){
@Override
public int compare(BookInfo book1, BookInfo book2) {
return book1.getTitle().compareTo(book2.getTitle());
}
});
with a custom Comparator, but I cannot use the compareTo
method for doubles/ints. How would I implements this, or change it so I can compare doubles/ints?