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));
}
stream
于 2020-10-15 10:16:55 首次发布