假设我喜欢:
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;
}
我想先按List<MyState>
然后再按MyState::date
对映射值MyState::state
进行排序
答案 0 :(得分:7)
您可以这样做:
Comparator<MyState> comparator = Comparator.comparing(MyState::getDate)
.thenComparing(MyState::getState);
map.values()
.forEach(l -> l.sort(comparator));