List<DemoPojo> list = new ArrayList<>();
DemoPojo tmpe1 = new DemoPojo(1,"苹果1");
DemoPojo tmpe2 = new DemoPojo(1,"苹果2");
DemoPojo tmpe3 = new DemoPojo(2,"苹果3");
DemoPojo tmpe4 = new DemoPojo(3,"苹果4");
DemoPojo tmpe5 = new DemoPojo(4,"苹果5");
list.add(tmpe1);
list.add(tmpe2);
list.add(tmpe3);
list.add(tmpe4);
list.add(tmpe5);
//lombok常见用法 list转map 分组类型
Map<Integer, List<DemoPojo>> collect = list.stream().collect(Collectors.groupingBy(DemoPojo::getId));
System.out.println(collect);
//list转map 去重
Map<Integer, DemoPojo> collect1 = list.stream().collect(Collectors.toMap(DemoPojo::getId, a -> a, (k1, k2) -> k2));
System.out.println(collect1);
这边去重取后一个id 可以看到 实体为苹果2的
//过滤
List<DemoPojo> c = list.stream().filter(a -> a.getName().equals("苹果4")).collect(Collectors.toList());
System.out.println(c);
//遍历 可以进行插入等操作
System.out.println("---------------------------------------------分割------------------------------------------");
list.stream().forEach(a-> System.out.println(a));
暂时这些 后续更新