brainfrz icon

Untitled

brainfrz | PRO | 10/16/15 11:11:05 PM UTC | 0 ⭐ | 818 👁️ | Never ⏰ | []
text |

510 B

|

None

|

0 👍

/

0 👎

    public static Comparator<Book> sortByTitle = (Book book1, Book book2) -> {
        String bookTitle1 = book1.getTitle().toLowerCase();
        if (bookTitle1.contains("the ")) {
            bookTitle1 = bookTitle1.substring(4, bookTitle1.length());
        }
         String bookTitle2 = book2.getTitle().toLowerCase();
        if (bookTitle2.contains("the ")) {
            bookTitle2 = bookTitle2.substring(4, bookTitle2.length());
        }
         return bookTitle1.compareTo(bookTitle2);
    };

Comments