当前位置:网站首页>list分割成满足和不满足条件的集合(partitioningBy)
list分割成满足和不满足条件的集合(partitioningBy)
2022-07-01 18:47:00 【码农巅峰】
一:集合对象实体
package cn.nhdc.cloud.common.annotation;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@NoArgsConstructor
@AllArgsConstructor
@Data
@Builder
public class Order {
/**
* 订单id
*/
private String orderId;
/**
* 订单名称
*/
private String orderName;
/**
* 订单类型 1为美团 2其他
*/
private String orderType;
}
二:运行案例
package cn.nhdc.cloud.common.annotation;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
public class Test11 {
public static void main(String[] args) {
List<Order> orders = new ArrayList<Order>() {
{
add(Order.builder().orderId("1").orderName("订单1").orderType("1").build());
add(Order.builder().orderId("2").orderName("订单2").orderType("1").build());
add(Order.builder().orderId("3").orderName("订单3").orderType("1").build());
add(Order.builder().orderId("4").orderName("订单4").orderType("1").build());
add(Order.builder().orderId("5").orderName("订单5").orderType("1").build());
add(Order.builder().orderId("6").orderName("订单6").orderType("2").build());
add(Order.builder().orderId("7").orderName("订单7").orderType("2").build());
add(Order.builder().orderId("8").orderName("订单8").orderType("3").build());
}};
//按照条件分割 满足和不满足条件的两个集合
Map<Boolean, List<Order>> collect = orders.parallelStream().collect(Collectors.partitioningBy(order -> "1".equals(order.getOrderType())));
System.err.println(collect);
}
}
三:运行结果
{
false=[Order(orderId=6, orderName=订单6, orderType=2), Order(orderId=7, orderName=订单7, orderType=2), Order(orderId=8, orderName=订单8, orderType=3)],
true=[Order(orderId=1, orderName=订单1, orderType=1), Order(orderId=2, orderName=订单2, orderType=1), Order(orderId=3, orderName=订单3, orderType=1), Order(orderId=4, orderName=订单4, orderType=1), Order(orderId=5, orderName=订单5, orderType=1)]
}
边栏推荐
- 安装sharp报错
- DS Transunet:用于医学图像分割的双Swin-Transformer U-Net
- H264 encoding profile & level control
- PowerDesigner设计Name和Comment 替换
- SQL 入门计划-1-选择
- DS transunet: Dual Swing transformer u-net for medical image segmentation
- JS ternary expression complex condition judgment
- torch. nn. functional. Interpolate function
- Wireshark packet analysis TCP, FTP
- Interview question 16.16 Partial sorting - Double finger needling
猜你喜欢

大厂音视频职位面试题目--今日头条

解决VSCode下载慢或下载失败的问题

Why has instagram changed from a content sharing platform to a marketing tool? How do independent sellers use this tool?

A brief understanding of white box encryption technology

Uni app product classification

实例讲解将Graph Explorer搬上JupyterLab

118. Yanghui triangle

Shell advanced

GC垃圾回收

wireshark报文分析tcp,ftp
随机推荐
Interview questions shared in today's group
音频编解码基础知识
[untitled]
Bao, what if the O & M 100+ server is a headache? Use Xingyun housekeeper!
mysql 报错 Can‘t create table ‘demo01.tb_Student‘ (errno: 150)*
P2433 【深基1-2】小学数学 N 合一
Process steps of vibrating wire acquisition module for measuring vibrating wire sensor
[research materials] iResearch tide Watching: seven major trends in the clothing industry - Download attached
How to configure webrtc video streaming format for easygbs, a new version of national standard gb28181 video platform?
After studying 11 kinds of real-time chat software, I found that they all have these functions
振弦采集模塊測量振弦傳感器的流程步驟
Oracle physical architecture
科技T3国产平台!成功搭载“翼辉国产实时系统SylixOS”
PowerDesigner设计Name和Comment 替换
Use the uni app demo provided by Huanxin to quickly realize one-on-one chat
Uni app product classification
毕业季 | 华为专家亲授面试秘诀:如何拿到大厂高薪offer?
再回顾集合容器
音视频、编解码相关电子书、小工具,打包奉送!
一个悄然崛起的国产软件,低调又强大!