当前位置:网站首页>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)]
}
边栏推荐
- DTD modeling
- H264 encoding profile & level control
- 新增订单如何防止重复提交
- Why has instagram changed from a content sharing platform to a marketing tool? How do independent sellers use this tool?
- js三元表达式复杂条件判断
- 新窗口打开页面-window.open
- OpenCV视频质量检测--清晰度检测
- Transaction isolation level gap lock deadlock
- Image acquisition and playback of coaxpress high speed camera based on pxie interface
- 【无标题】
猜你喜欢
Use the uni app demo provided by Huanxin to quickly realize one-on-one chat

Is Dao safe? Build finance encountered a malicious governance takeover and was looted!

After studying 11 kinds of real-time chat software, I found that they all have these functions

The key to the success of digital transformation enterprises is to create value with data

有意思了!数据库也搞Serverless!

Test self-study people must see: how to find test items in software testing?

Why must we move from Devops to bizdevops?

通过js实现金字塔(星号金字塔,回文对称数字金字塔)

DDR4 test-2

解决VSCode下载慢或下载失败的问题
随机推荐
[research materials] Huawei Technology ICT 2021: at the beginning of the "Yuan" year, the industry is "new" -- download attached
PowerDesigner设计Name和Comment 替换
Why has instagram changed from a content sharing platform to a marketing tool? How do independent sellers use this tool?
Regular expression =regex=regular expression
Leetcode 1380 lucky numbers in matrix [array] the leetcode path of heroding
Opencv video quality diagnosis - VIDEO occlusion diagnosis
音频编解码基础知识
Wireshark packet analysis TCP, FTP
Is Dao safe? Build finance encountered a malicious governance takeover and was looted!
Using win7 vulnerability to crack the system login password
GaussDB(for MySQL) :Partial Result Cache,通过缓存中间结果对算子进行加速
Optaplanner learning notes (I) case cloud balance
Optimization of video streaming with repeated requests in the case of unstable easygbs network
解决VSCode下载慢或下载失败的问题
mysql 報錯 Can‘t create table ‘demo01.tb_Student‘ (errno: 150)*
一文读懂C语言中的结构体
使用 Kibana Timelion 进行时间序列分析
Interview question 16.16 Partial sorting - Double finger needling
Basic knowledge of audio coding and decoding
微信小程序 navigator点击后有阴影 ,去掉navigator阴影效果