brainfrz

Untitled

Oct 16th, 2015
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. public static Comparator<Book> sortByTitle = (Book book1, Book book2) -> {
  2. String bookTitle1 = book1.getTitle().toLowerCase();
  3. if (bookTitle1.contains("the ")) {
  4. bookTitle1 = bookTitle1.substring(4, bookTitle1.length());
  5. }
  6.  
  7. String bookTitle2 = book2.getTitle().toLowerCase();
  8. if (bookTitle2.contains("the ")) {
  9. bookTitle2 = bookTitle2.substring(4, bookTitle2.length());
  10. }
  11.  
  12. return bookTitle1.compareTo(bookTitle2);
  13. };
Advertisement
Add Comment
Please, Sign In to add comment