取出list中某几个字段生成一个新的list<对象>
List<DemoTestPo> demoTestList = list.stream().map(v->{
DemoTestPo po = new DemoTestPo();
po.setImageName(v.getImageName());
po.setImageType(v.getImageType());
po.setImageUrl(v.getImageUrl());
po.setRegistNo(v.getRegistNo());
return po;
}).collect(Collectors.toList());
将list中某几个字段拼接而成一个新的list
List<String> valueList = list.stream().map(k->
k.getCompanyName()+";"+k.getLineName()+";"+k.getClassify()).collect(Collectors.toList());
将list中某几个字段拼接而成一个新的list 并去重
List<String> noRepeatValueList = list.stream().map(k->
k.getCompanyName()+";"+k.getLineName()+";"+k.getClassify()).distinct().collect(Collectors.toList());
List productList = new ArrayList<>();
objList.parallelStream().collect(Collectors.groupingBy(ImportProductForm::getProductCode, Collectors.toList()))
.forEach((productCode, transfer)->{
transfer.stream().reduce((a, b)-> new ImportProductForm(a.getProductCode(),a.getProdTime(),a.getExpireTime(),a.getLotNo(),a.getSerialNo(),a.getUdi(),a.getNumber()+b.getNumber())).isPresent(productList::add)
});
本文介绍如何使用 Java Stream API 处理集合数据,包括提取特定字段生成新列表、字段拼接及去重等操作,通过实例展示了 Stream API 的强大功能。
3310

被折叠的 条评论
为什么被折叠?



