当前位置:网站首页>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)]
}
边栏推荐
- 1592 例题1 国王(Sgu223 LOJ10170 LUOGU1896 提高+/省选-) 暴力思考 状压DP 01背包
- 面试题篇一
- 墨天轮沙龙 | 清华乔嘉林:Apache IoTDB,源于清华,建设开源生态之路
- Using win7 vulnerability to crack the system login password
- CMU AI PhD first year summary
- Compile ffmpeg source code with msys+vs2019 under win10
- H264 encoding profile & level control
- JVM memory model
- Use the uni app demo provided by Huanxin to quickly realize one-on-one chat
- 对象的创建
猜你喜欢
毕业季 | 华为专家亲授面试秘诀:如何拿到大厂高薪offer?
[Mori city] random talk on GIS data (I)
Audio and video, encoding and decoding related e-books, gadgets, packaged for free!
118. 杨辉三角
Mo Tianlun salon | Tsinghua qiaojialin: Apache iotdb, originated from Tsinghua, builds an open source ecological road
Cookie和Session的相关概念
GC garbage collection
通过js实现金字塔(星号金字塔,回文对称数字金字塔)
A brief understanding of white box encryption technology
[research materials] Huawei Technology ICT 2021: at the beginning of the "Yuan" year, the industry is "new" -- download attached
随机推荐
118. 杨辉三角
新窗口打开页面-window.open
Interview questions for audio and video positions in Dachang -- today's headline
CMU AI PhD first year summary
Salesmartly has some tricks for Facebook chat!
大厂音视频职位面试题目--今日头条
Wechat applet realizes keyword highlighting
Analysis of GetMessage underlying mechanism
qobject_cast用法
Opencv video quality diagnosis - VIDEO occlusion diagnosis
利用win7漏洞进行系统登录密码破解
[research data] observation on the differences of health preservation concepts among people in 2022 - Download attached
Object creation
Crunch简介、安装,使用Crunch制作密码字典
The key to the success of digital transformation enterprises is to create value with data
Introduction and installation of crunch, and making password dictionary with crunch
ffmpeg 错误码
Technology T3 domestic platform! Successfully equipped with "Yihui domestic real-time system sylixos"
事务隔离级别 gap锁 死锁
Shell advanced