当前位置:网站首页>List is divided into sets that meet and do not meet conditions (partitioningby)
List is divided into sets that meet and do not meet conditions (partitioningby)
2022-07-01 19:50:00 【Manong peak】
One : Collection object entity
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 {
/**
* Order id
*/
private String orderId;
/**
* Name of the order
*/
private String orderName;
/**
* Order type 1 For meituan 2 other
*/
private String orderType;
}
Two : Running cases
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(" Order 1").orderType("1").build());
add(Order.builder().orderId("2").orderName(" Order 2").orderType("1").build());
add(Order.builder().orderId("3").orderName(" Order 3").orderType("1").build());
add(Order.builder().orderId("4").orderName(" Order 4").orderType("1").build());
add(Order.builder().orderId("5").orderName(" Order 5").orderType("1").build());
add(Order.builder().orderId("6").orderName(" Order 6").orderType("2").build());
add(Order.builder().orderId("7").orderName(" Order 7").orderType("2").build());
add(Order.builder().orderId("8").orderName(" Order 8").orderType("3").build());
}};
// Split by condition Two sets that satisfy and do not satisfy conditions
Map<Boolean, List<Order>> collect = orders.parallelStream().collect(Collectors.partitioningBy(order -> "1".equals(order.getOrderType())));
System.err.println(collect);
}
}
3、 ... and : Running results
{
false=[Order(orderId=6, orderName= Order 6, orderType=2), Order(orderId=7, orderName= Order 7, orderType=2), Order(orderId=8, orderName= Order 8, orderType=3)],
true=[Order(orderId=1, orderName= Order 1, orderType=1), Order(orderId=2, orderName= Order 2, orderType=1), Order(orderId=3, orderName= Order 3, orderType=1), Order(orderId=4, orderName= Order 4, orderType=1), Order(orderId=5, orderName= Order 5, orderType=1)]
}
边栏推荐
- Nat penetration of gb28181
- windows环境 redis安装和启动(后台启动)
- 使用 Kibana Timelion 进行时间序列分析
- The key to the success of digital transformation enterprises is to create value with data
- 音频编解码基础知识
- HLS4ML进入方法
- [untitled]
- Basic use of MySQL
- 2022/5/23-2022/5/30
- [research materials] Huawei Technology ICT 2021: at the beginning of the "Yuan" year, the industry is "new" -- download attached
猜你喜欢

How to correctly use vertx to operate redis (3.9.4 with source code analysis)

再回顾集合容器

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

Wireshark packet analysis TCP, FTP

【无标题】

Introduction and installation of crunch, and making password dictionary with crunch

EasyCVR通过国标GB28181协议接入设备,出现设备自动拉流是什么原因?
![[Mori city] random talk on GIS data (I)](/img/4d/1ed4bbf397b8d756c91241705528de.jpg)
[Mori city] random talk on GIS data (I)

安装sharp报错

SQL 入门计划-1-选择
随机推荐
How to add transactions in JDBC
PowerDesigner设计Name和Comment 替换
[research data] observation on the differences of health preservation concepts among people in 2022 - Download attached
Introduction and installation of crunch, and making password dictionary with crunch
使用 Kibana Timelion 进行时间序列分析
JS 之 常用内置类的使用
Process steps of vibrating wire acquisition module for measuring vibrating wire sensor
[exercise] HashSet
【sql优化】with as 和 临时表的区别
Wechat applet navigator has a shadow after clicking. Remove the shadow effect of navigator
How to use console Log print text?
PowerDesigner design name and comment replacement
703. The k-th element in the data flow
Axure does not display catalogs
墨天轮沙龙 | 清华乔嘉林:Apache IoTDB,源于清华,建设开源生态之路
Why has instagram changed from a content sharing platform to a marketing tool? How do independent sellers use this tool?
科技T3国产平台!成功搭载“翼辉国产实时系统SylixOS”
Oracle physical architecture
Bao, what if the O & M 100+ server is a headache? Use Xingyun housekeeper!
一文读懂C语言中的结构体