概述
平时通常会用到Stream做数据处理
demo
public static void main(String[] args) {
List<SysMenu> menuList = new ArrayList<>();
SysMenu menu = new SysMenu();
menu.setPerms("222,333");
menuList.add(menu);
menu = new SysMenu();
menu.setPerms(null);
menuList.add(menu);
List<String> strings = menuList.stream().map(SysMenu::getPerms).collect(Collectors.toList());
Set<String> set = menuList.stream().flatMap((e) -> {
if (StrUtil.isBlank(e.getPerms())) {
return null;
}
return Arrays.stream(e.getPerms().trim().split(StrUtil.COMMA));
}
).collect(Collectors.toSet());
set.forEach(System.out::println);
}
最后
以上就是魁梧黄蜂最近收集整理的关于List Stream flatMap的使用的全部内容,更多相关List内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复