stream

 public static void main(String[] args) {
        store.setLabels(String.join(",",labelList));
        ArrayList<String> list = Lists.newArrayList();
        list.add("");
        list.add("1");
        list.add("2");
        list.add("");
        list.stream().forEach(System.out::println);
        list.stream().forEach((v)->{
            System.out.println(v);
        });
        //:: 方法需要传参
        list.forEach(CoreClassroomsController::g);
        list.forEach(f->{  //等价于
            CoreClassroomsController.g(f);
        });
        //count 数量
        long count = list.stream().filter(i -> i.isEmpty()).count();
        list.stream().map(g -> g + g).forEach(System.out::println);
        //map 最后的结果为 g+g
        list.parallelStream().map(g->g+g).forEach(System.out::println);
        //filter 过滤 Collectors 将结果转换为list
        List<String> collect = list.stream().filter(i ->i.equals("1")).collect(Collectors.toList());
        List<Student> list1 = new ArrayList<>();
        Student s1 = new Student("zhangsan",3);
        list1.add(s1);
        Student s2 = new Student("lisi",1);
        list1.add(s2);
        Student s3 = new Student("lining",2);
        list1.add(s3);
        Student s4 = new Student("lining",2);
        list1.add(s4);
        //sorted 排序
        List<Student> sortDesList = list1.stream().sorted(Comparator.comparingInt(Student::getAge).reversed()).collect(Collectors.toList());
        sortDesList.forEach(i-> System.out.println(i.getAge()));
        //获取某个属性的集合
        List<Long> ids = list.stream().map(InterDevicePlacePageDto::getBuildingId).collect(Collectors.toList());
//某个字段数量总和
list.stream().collect(Collectors.summingLong(CouponPackageEntity::getRemain));
等价于 d.setCouponPackageNum(couponPackageEntities.stream().mapToLong(CouponPackageEntity::getCouponPackageNum).sum());
//获取字段最大值
Integer sortNo = list.stream().max(Comparator.comparingInt(CouponPackageBatchDetailEntity::getSortNo)).get().getSortNo();
        //分组
Map<Long, List<ParentBindStudentDTO>> map = parentBindStudentsByparentIds.stream().collect(Collectors.groupingBy(ParentBindStudentDTO::getParentId));
	Map<String, ErpPlatformSysPara> paramMap = erpPlatformSysParas.stream().collect(Collectors.toMap(ErpPlatformSysPara::getParamId, erpPlatformSysPara -> erpPlatformSysPara));
//多key
Map<Integer, List<Integer>>  caseTypeClassMap = classlist.stream().collect(Collectors.toMap(ErpAuditClass::getCaseType,   // 此时的value 为集合,方便重复时操作
					a ->  {
						List<Integer> classids = new ArrayList<>();
						classids.add(a.getId());
						return classids;
					},
					// 重复时将现在的值全部加入到之前的值内
					(List<Integer> value1, List<Integer> value2) -> {
						value1.addAll(value2);
						return value1;
					}
			));
    }
    public static void g(String f){
        System.out.println("g");
    }
    //异步处理
        new Thread(() -> { 
    }).start();
    //list分页
   List<List<CouponCodeList>> partition = Lists.partition(couponCodeLists, 500);
            partition.forEach(partitionList -> 
   couponCodeListService.saveCouponCodeListBath(partitionList));
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值