我有一张地图Map<K, List<V>> inputMap
我希望在存储到列表之前对列表进行排序
List<String> outputList = inputMap.keySet()
.stream()
.filter(Objects::nonNull)
.map(key -> (key + "==" + inputMap.get(key).sort(c);))
.sorted()
.collect(Collectors.toList());
答案 0 :(得分:3)
这个怎么样?
List<String> outputList = inputMap.keySet().stream()
.filter(Objects::nonNull)
.map(key -> key + "=="
+ inputMap.get(key).stream().sorted(c)
.collect(Collectors.toList()))
.sorted()
.collect(Collectors.toList());
或
List<String> outputList = inputMap.keySet().stream()
.filter(Objects::nonNull)
.map(key -> key + "=="
+ inputMap.get(key).stream().sorted(c)
.map(Object::toString)
.collect(Collectors.joining(", ","[","]")))
.sorted()
.collect(Collectors.toList());