当前位置:网站首页>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)]
}
边栏推荐
- How can a programmer grow rapidly
- Interview question 16.16 Partial sorting - Double finger needling
- Define dichotomy lookup
- The key to the success of digital transformation enterprises is to create value with data
- 1592 例题1 国王(Sgu223 LOJ10170 LUOGU1896 提高+/省选-) 暴力思考 状压DP 01背包
- Class loading mechanism
- 为定时器和延时器等其它情况的回调函数绑定当前作用域的this
- What is the essential difference between Bi development and report development?
- JS的Proxy
- Transaction isolation level gap lock deadlock
猜你喜欢
Bind this of the current scope for callback functions in other cases such as timers and delayers
Use the uni app demo provided by Huanxin to quickly realize one-on-one chat
windows环境 redis安装和启动(后台启动)
Optimization of video streaming with repeated requests in the case of unstable easygbs network
[research data] observation on the differences of health preservation concepts among people in 2022 - Download attached
P2433 [deep foundation 1-2] primary school mathematics n in one
[research materials] national second-hand housing market monthly report January 2022 - Download attached
科技T3国产平台!成功搭载“翼辉国产实时系统SylixOS”
振弦采集模块测量振弦传感器的流程步骤
Regular expression =regex=regular expression
随机推荐
JS 之 常用内置类的使用
JS proxy
Wireshark packet analysis TCP, FTP
Object creation
Example explanation: move graph explorer to jupyterlab
Opencv video quality detection -- sharpness detection
What is the essential difference between Bi development and report development?
wireshark报文分析tcp,ftp
Bao, what if the O & M 100+ server is a headache? Use Xingyun housekeeper!
Redo和Undo的区别
Introduction and installation of crunch, and making password dictionary with crunch
[research materials] iResearch tide Watching: seven major trends in the clothing industry - Download attached
DDR4 test-2
How to add transactions in JDBC
新增订单如何防止重复提交
[research materials] Huawei Technology ICT 2021: at the beginning of the "Yuan" year, the industry is "new" -- download attached
为定时器和延时器等其它情况的回调函数绑定当前作用域的this
MySQL signale une erreur can 't create table' demo01. TB Étudiant '(errno: 150)
【sql优化】with as 和 临时表的区别
Review the collection container again