当前位置:网站首页>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)]
}
边栏推荐
- How to correctly use vertx to operate redis (3.9.4 with source code analysis)
- Time series analysis using kibana timelion
- wireshark报文分析tcp,ftp
- P2433 【深基1-2】小学数学 N 合一
- 音视频、编解码相关电子书、小工具,打包奉送!
- Unreal Engine packaging project
- Salesmartly has some tricks for Facebook chat!
- Regular expression =regex=regular expression
- Optimization of video streaming with repeated requests in the case of unstable easygbs network
- GB28181之SIP协议
猜你喜欢

JS 之 常用内置类的使用

Mo Tianlun salon | Tsinghua qiaojialin: Apache iotdb, originated from Tsinghua, builds an open source ecological road

今日群里分享的面试题

HLS4ML报错The board_part definition was not found for tul.com.tw:pynq-z2:part0:1.0.

Axure does not display catalogs

Image acquisition and playback of coaxpress high speed camera based on pxie interface

SQL 入门计划-1-选择

Shell advanced
![Leetcode 1380 lucky numbers in matrix [array] the leetcode path of heroding](/img/56/0c7f39406814b5bf92eca5f6670e10.jpg)
Leetcode 1380 lucky numbers in matrix [array] the leetcode path of heroding

GC garbage collection
随机推荐
音频编解码基础知识
Use the uni app demo provided by Huanxin to quickly realize one-on-one chat
Ffmpeg error code
P2433 [deep foundation 1-2] primary school mathematics n in one
Class loading mechanism
H264编码profile & level控制
Why must we move from Devops to bizdevops?
New window open page -window open
MySQL reports an error can't create table 'demo01 tb_ Student‘ (errno: 150)*
Define dichotomy lookup
毕业季 | 华为专家亲授面试秘诀:如何拿到大厂高薪offer?
DDR4 test-2
Interview question 16.16 Partial sorting - Double finger needling
Compile ffmpeg source code with msys+vs2019 under win10
Interview questions shared in today's group
JS ternary expression complex condition judgment
解决VSCode下载慢或下载失败的问题
Oracle物理体系结构
新窗口打开页面-window.open
DTD modeling