Page 1 of 1

About Question enthuware.ocpjp.v17.2.3321 :

Posted: Sat Nov 19, 2022 10:07 am
by TarunP
books.sort(Comparator.comparing(Book::getGenre).thenComparing(Book::getTitle).reversed());

This reverses both the values (Genre and Title).
How do I reverse only the Title? Thanks

//result
[{non-fiction':Uri'}, {non-fiction':Becoming'}, {fiction':The Outsider'}, {fiction':Cujo'}]

Re: About Question enthuware.ocpjp.v17.2.3321 :

Posted: Sun Nov 20, 2022 9:47 pm
by admin
Instead of calling reversed() at the end, pass the reverse compartor in thenComparing.