stream流笔记
map 转换元素
List<Long> ids = list.stream().map(DictionaryMetaPO::getId).collect(Collectors.toList());
Collectors.joining 拼接字符串
String s = list.stream().map(DictionaryMetaPO::getValue).collect(Collectors.joining("-"));
sorted 排序
// e1-e2升序,e2-e1降序
List<DictionaryMetaPO> list = list.stream().sorted((e1, e2) -> e2.getType() - e1.getType()).collect(Collectors.toList());
Collectors.toMap 收集元素成Map
Map<Long, String> map = list.stream().collect(Collectors.toMap(DictionaryMetaPO::getId, DictionaryMetaPO::getValue, (u, v) -> u));
Collectors.groupingBy() 分组
// 根据字段分组
Map<Integer, List<DictionaryMetaPO>> map = list.stream().collect(Collectors.groupingBy(DictionaryMetaPO::getType));
//根据字段分组后,处理分组后数据
Map<Integer, List<String>> map = list.stream().collect(Collectors.groupingBy(DictionaryMetaPO::getType,
Collectors.mapping(DictionaryMetaPO::getValue, Collectors.toList())));
标签:map,stream,Collectors,DictionaryMetaPO,list,笔记,collect
From: https://www.cnblogs.com/fgbear/p/17253466.html