//Optional 的使用及filter的使用小记
Optional<YourEntity> result= list.stream()
.filter(a -> "xx".equals(a.getName()))
.findFirst();
//获取对象
if (result.isPresent()) {
YourEntity a = result.get();
}
//通过 ifPresent 直接处理结果集
Optional<YourEntity> result2= list.stream()
.filter(a -> "xx".equals(a.getName()))
.findFirst()
.ifPresent(a -> {
a.setName("yy");
})
//得到过滤后的集合
List<YourEntity> result3= list.stream()
.filter(a -> "xxx".equals(a.getName()))
.collect(Collectors.toList());
//获取对象中所有id的集合
List<String> ids = list.stream()
.map(YourEntity::getId)
.collect(Collectors.toList());
//获取Map
Map<String, YourEntity> mapResult = list.stream()
.filter(a-> StringUtil.isNotEmpty(a.getName()))
.collect(Collectors.toMap(YourEntity::getId, a -> a));