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'}]
About Question enthuware.ocpjp.v17.2.3321 :
Moderator: admin
-
- Posts: 1
- Joined: Sat Nov 19, 2022 8:14 am
- Contact:
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v17.2.3321 :
Instead of calling reversed() at the end, pass the reverse compartor in thenComparing.
Who is online
Users browsing this forum: No registered users and 6 guests