Suppose I have like :
Map<String, List<MyState>> map = new HashMap<>();
map.computeIfAbsent(key, file -> new ArrayList<>()).add(myState);
map.put("aa",list1..)
map.put("bb",list2..)
map.put("cc",list3..)
public class MyState {
private String state;
private String date;
}
I want to sort the map values List<MyState>
by MyState::date
and then by MyState::state
You can do so with:
Comparator<MyState> comparator = Comparator.comparing(MyState::getDate)
.thenComparing(MyState::getState);
map.values()
.forEach(l -> l.sort(comparator));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With