有没有一种方法可以按值进行地图条目排序,其中值是集合?我希望按其集合大小对条目进行排序。 我迄今为止的代码:
public Map<Object, Collection<Object>> sortByCollectionSize() {
return myMap.entrySet().stream().sorted(Map.Entry.<Object, Collection<Object>>comparingByValue())
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new));
}