List<String> temp = sList.stream().map(x -> x.getId()).distinct().collect(Collectors.toList());
流操作,前面是展开 map,对指定id进行去重,最后转为list
其中 List<Stu> sList
Stu为对象,id 和name两个字段
其他操作参见:jdk stream
再有例子:
Optional<Integer> score = studentList.stream()
.map(Student :: getScore)
.filter(s -> s<60)
.reduce((a,b) -> a+b);
参考:https://blog.csdn.net/zl_stepbystep/article/details/82729657
流操作,前面是展开 map,对指定id进行去重,最后转为list
其中 List<Stu> sList
Stu为对象,id 和name两个字段
其他操作参见:jdk stream
再有例子:
Optional<Integer> score = studentList.stream()
.map(Student :: getScore)
.filter(s -> s<60)
.reduce((a,b) -> a+b);
参考:https://blog.csdn.net/zl_stepbystep/article/details/82729657