Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
131 views
in Technique[技术] by (71.8m points)

怎么把List<LinkedHashMap>通过stream转为一个List<List<String>>

List<LinkedHashMap<String,String>> 需要将LinkedHashMap中的value取出来,最后转成List<List<String>>


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

// collection可以用的话
List<Collection<String>> collect1 = list.stream().map(LinkedHashMap::values).collect(Collectors.toList());
// 转list
List<List<String>> collect2 = list.stream().map(LinkedHashMap::values).map(ArrayList::new).collect(Collectors.toList());
// 合并所有value
List<String> collect3 = list.stream().map(LinkedHashMap::values).flatMap(Collection::stream).collect(Collectors.toList());


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...