java8 stream流的使用
2024-09-08 17:55:54
List<Paper> list = new ArrayList<>();
list.add(new Paper("m",2L));
list.add(new Paper("a",1L));
list.add(new Paper("j",3L));
list.add(new Paper("t",4L));
list.add(new Paper("b",5L));
遍历:
list.stream().forEach(item ->{
});
排序: List<Paper> collect = list.stream().sorted(Comparator.comparing(Paper::getPaperName)).collect(Collectors.toList());
分组:Map<String, List<Paper>> collect =list.stream().collect(Collectors.groupingBy(Paper::getPY))
最大最小值:
Optional<Paper> max =list.stream().max(Comparator.comparing(Paper::getPaperName));
if (max.isPresent()) {//防止空指针
......
}
转换map:
Map<Long, String> collect2 = list.stream().collect(Collectors.toMap(Paper::getPaperId, Paper::getPaperName));
过滤:
Optional<Paper> min = x.getSchedulingList().stream().filter(s -> s.id()>=1).min(Comparator.comparing(Paper::getPaperName));
价格类属性累加:
orderList.stream().map(OrderEntity::getRealFee).reduce(BigDecimal.ZERO, BigDecimal::add);
判断重复重:
if(partitionCamera.stream().anyMatch(item->
item.getChannelNo().compareTo(deviceCamera.getChannelNo())==0 && item.getDeviceSerial().equals(deviceCamera.getDeviceSerial()))){
}
转map避免控指针
Map<String, String> map = xdsList.stream().collect(Collectors.toMap(XdsDtuEntity::getXMac, e->e.getXDtuDescribe()==null?"":e.getXDtuDescribe()));
将集合转为map 属性做键 对象做值
hutool 5.5.2版本
CollStreamUtil.toIdentityMap(hzOptionList, HzOption::getId)
最新文章
- caffe源码解析
- java画图之曲线拖动
- js③
- 说说Timing这回事(转载)
- How-to: disable the web-security-check in Chrome for Mac
- CSS 确定选中变红色
- mysql 获取一个表中缺失的最小编号
- RegexOne
- 美H1B签证额满,硕士以上学位仍可申请
- core dump + LINUX 内核系列博客
- (转载)关于ArrayList的5道面试题
- Java IntelliJ IDEA 不能显示项目里的文件结构解决办法
- C# Winform中DataGridView的DataGridViewCheckBoxColumn CheckBox选中判断
- 使用three.js加载3dmax资源,以及实现场景中的阴影效果
- Spark源码分析 之 Driver和Excutor是怎么跑起来的?(2.2.0版本)
- x86汇编语言实践(3)
- BBS论坛(二十八)
- C# 数组与集合的区别
- LGP2801 教主的魔法
- 根据日志分析异常:There is already &#39;XXX&#39; bean method