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: 10102
- 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.
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: Bing [Bot] and 33 guests