1、寻找List符合要求的对象
//未查到就会报错,抛出异常信息,与预期不一致
A a = bList().stream().filter(b -> "test".equals(b.getName())).findAny().get();
a、针对上边这种方式修改
A a =bList().stream().filter(b->"test".equals(b.getName())).findAny().orElse(null);
//扩展对象
List<Map<String,String>> maps = new HashMap();
Map<String, String> objectObjectHashMap = new HashMap<>();
objectObjectHashMap.put("num","0");
maps.stream().filter(e -> Integer.valueOf(1).equals(e.get("level"))).findAny().orElse(objectObjectHashMap).get("num")
2、计算count值
//对对象进行分组求和
Map<String, Long> theMap = exposedAssetsDataInfos.stream().collect(Collectors.groupingBy(e -> e.getPublicIp() + e.getAffiliatedTwoDeptName(), Collectors.counting()));
3、查询重复的值,获取重复的数据
//查询重复的某个值,转换成List对象
List<String> theSameList = theMap.entrySet().stream().filter(e -> e.getValue() > 1).map(e -> e.getKey()).collect(Collectors.toList());
标签:Stream,stream,get,List,objectObjectHashMap,equals,filter
From: https://www.cnblogs.com/cmsdnbog/p/17682302.html