Java8 Stream流常见操作--持续更新中

创建新数组

List<Fruit> newList = fruits.stream()
    .map(f -> new Fruit(f.getId(), f.getName() + "s", f.getCountry()))
    .collect(Collectors.toList())

筛选数组

Map<Boolean, List<TransferData>> preAvg = list.stream()
        .collect(Collectors.groupingBy(x -> x.getStatus() != 3));
List<TransferData> trueList = preAvg.get(true);

筛选数组2

List<TypeAttribute> result = list.stream().filter((e) ->
   e.getIsDeleted() != 1
).collect(Collectors.toList());

筛选不为空

list.stream().filter(e -> StringUtils.isNotBlank(e.getUrl())).collect(Collectors.toList())

数组移除指定元素

移除指定元素

List数组求和

long zsSum = zs.stream().reduce(Integer::sum).orElse(0);

初始化list

List<Integer> list = Stream.of(1, 2, 3).collect(Collectors.toList());

针对某个属性对倒序

List<TransferData> sList = trueList.stream().sorted(Comparator.comparing(TransferData::getCreateTime).reversed()).collect(Collectors.toList());
List<TransferData> falseList = preAvg.get(false);

获取数组对象的所有id

List<Long> delIds = delList.stream().map(TypeAttribute::getId).collect(Collectors.toList());

你可能感兴趣的:(JAVA,java)