基础数据
List<Item> list = new ArrayList<>();
list.add(new Item(11,"aa"));
list.add(new Item(10,"bb"));
list.add(new Item(18,"cc"));
list.add(new Item(9,"dd"))
1.根据id排序
List<Item> collect= list.stream().sorted(Comparator.comparing(Item::getId)).collect(Collectors.toList());
2.集合遍历
collect.forEach(e->{
System.out.println(e.getId()+"_"+e.getName());
});
3.移除list中某个元素
list.removeIf(e -> e.getId() == 10);
4.快速打印
ArrayList<Integer> list = new ArrayList<>();
Collections.addAll(list, 1,2,3,4,5);
list.forEach(System.out::println);
最后
以上就是任性盼望最近收集整理的关于Lambda常用语法的全部内容,更多相关Lambda常用语法内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复