51,409
社区成员
发帖
与我相关
我的任务
分享 Map<String, List<A>> groupAndSort(List<A> list){
Map<String,List<A>> map = new HashMap<>();
for (A a : list) {
List<A> aList = map.get(a.groupName);
if(aList==null){
aList = new ArrayList<>();
}
aList.add(a);
map.put(a.groupName,aList);
}
for (String s : map.keySet()) {
List<A> finalList = map.get(s);
finalList.sort(new Comparator<A>() {
@Override
public int compare(A o1, A o2) {
return o1.value>o2.value?-1:1;
}
});
}
return map;
}