当前位置:网站首页>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)]
}
边栏推荐
猜你喜欢
随机推荐
GC垃圾回收
博途V16 获取系统时间转换成字符串
Battery simulation of gazebo robot
Shell advanced
Basic use of MySQL
After studying 11 kinds of real-time chat software, I found that they all have these functions
2022/6/8-2022/6/12
Bind this of the current scope for callback functions in other cases such as timers and delayers
今日群里分享的面试题
[research materials] Huawei Technology ICT 2021: at the beginning of the "Yuan" year, the industry is "new" -- download attached
Oracle physical architecture
新增订单如何防止重复提交
SIP protocol of gb28181
使用 Kibana Timelion 进行时间序列分析
JDBC中如何添加事务
Is Dao safe? Build finance encountered a malicious governance takeover and was looted!
qobject_cast用法
SQL 入门计划-1-选择
一个悄然崛起的国产软件,低调又强大!
毕业季 | 华为专家亲授面试秘诀:如何拿到大厂高薪offer?









