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);