1. 程式人生 > >java1.8 stream常用的方法記錄

java1.8 stream常用的方法記錄

1.從List<Map<String,String>>中取map的一個值,並用逗號拼接
List<Map<String, String>> sendZhusongIdList = dispatchDO.getSendZhusongIdList();
String sendZhusongName = 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());
String deptLeaderName = opinionList.stream().filter(x->"divisionHead".equals(x.getFieldKey()))map(x->x.getCreateUserName().toString()).collect(Collectors.joining(","));