java1.8 stream常用的方法记录


1.从List<Map<String,String>>中取map的一个值,并用逗号拼接

List<Map<String,String>>sendZhusongIdList=dispatchDO.getSendZhusongIdList();

StringsendZhusongName=sendZhusongIdList.stream().map(x->x.get("text")).collect(Collectors.joining(","));

System.err.println("sendZhusongName:"+sendZhusongName);

2.过滤后取出需要的值拼接成字符串

List<OpinionDO>opinionList=opinionService.listByMainId(map.get("ID").toString());StringdeptLeaderName=opinionList.stream().filter(x->"divisionHead".equals(x.getFieldKey()))map(x->x.getCreateUserName().toString()).collect(Collectors.joining(","));