list转map(分组并排序)方法一
public Map<String, List<FileKpiDetail>> selectKpi(Integer fileId){
List<FileKpiDetail> fileKpiDetails = fileKpiMapper.selectKpiByFileId(fileId);
return fileKpiDetails.stream().collect(Collectors.groupingBy(FileKpiDetail::getGroupName, LinkedHashMap::new, Collectors.toList()));
}
list转map 方法二
infoGroupMgmts = infoGroupMgmtMapper.selectList(null);
infoGroupMap = infoGroupMgmts.stream().collect(Collectors.toMap(v->String.valueOf(v.getId()), v->v));
以逗号分隔的id字符串,去重排序后转为int、Integer数组
String kpiIds = "1,2,3,4,5,6";
int[] intIds = Arrays.stream(kpiIds.split(",")).distinct().sorted().mapToInt(Integer::new).toArray();
Integer[] integerIds = Arrays.stream(kpiIds.split(",")).distinct().sorted().mapToInt(Integer::new).boxed().toArray(Integer[]::new);
根据id数组,找出id存在于List集合中的数据 anyMatch
public List<StaticKpiRes> getStaticKpiByIds(Integer[] ids){
return staticKpiRes.stream().filter(e -> Arrays.stream(ids).anyMatch(id -> id.equals(e.getId()))).collect(Collectors.toList());
}