jdk8表达式积累

集合排序使用 stream的sorted方法 通过方法引用指定排序的字段

 list.sort(Comparator.comparing(QuestionHisOptionDto::getOptionNo));

集合根据某一个字段去重复
通过treeset来去重,多个参数的话,后面添加多个方法引用

List<RoleMenuTreeDto> menuTreeDtos = roleMenuTreeDtos.stream()
                       .collect(Collectors
                        .collectingAndThen(Collectors.toCollection(() 
						-> new TreeSet<>(Comparator.comparing(RoleMenuTreeDto::getId))), ArrayList::new));

reduce统计

在这里插入代码片
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章