[英]How to sort generic list in java8
我有一個地圖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());
這個怎么樣?
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());
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.