当前位置:网站首页>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)]
}
边栏推荐
- MYSLQ十种锁,一篇文章带你全解析
- [SQL optimization] the difference between with as and temporary tables
- New window open page -window open
- February 15, 2022: sweeping robot. There is a floor sweeping robot in the room (represented by a grid). Each grid in the grid has two possibilities: empty and obstacles. The sweeping robot provides fo
- Leetcode 1380 lucky numbers in matrix [array] the leetcode path of heroding
- js三元表达式复杂条件判断
- wireshark报文分析tcp,ftp
- Proxy in ES6
- Live HLS protocol
- 【sql优化】with as 和 临时表的区别
猜你喜欢

一个悄然崛起的国产软件,低调又强大!

Introduction and installation of crunch, and making password dictionary with crunch
![[research materials] national second-hand housing market monthly report January 2022 - Download attached](/img/c8/a205ddc2835c87efa38808cf31f59e.jpg)
[research materials] national second-hand housing market monthly report January 2022 - Download attached

wireshark报文分析tcp,ftp

Technology T3 domestic platform! Successfully equipped with "Yihui domestic real-time system sylixos"

今日群里分享的面试题

JS proxy

墨天轮沙龙 | 清华乔嘉林:Apache IoTDB,源于清华,建设开源生态之路

Bind this of the current scope for callback functions in other cases such as timers and delayers

The key to the success of digital transformation enterprises is to create value with data
随机推荐
音视频、编解码相关电子书、小工具,打包奉送!
Ffmpeg audio related commands
Opencv video quality detection -- sharpness detection
【sql优化】with as 和 临时表的区别
Bao, what if the O & M 100+ server is a headache? Use Xingyun housekeeper!
Ffmpeg avframe to cv:: mat
Audio and video, encoding and decoding related e-books, gadgets, packaged for free!
HLS4ML报错The board_part definition was not found for tul.com.tw:pynq-z2:part0:1.0.
为定时器和延时器等其它情况的回调函数绑定当前作用域的this
P2433 【深基1-2】小学数学 N 合一
Interview question 1
JVM内存模型
Brpc understanding
[exercise] HashSet
Use the uni app demo provided by Huanxin to quickly realize one-on-one chat
tensorflow报错Could not load dynamic library ‘libcudnn.so.8
毕业季 | 华为专家亲授面试秘诀:如何拿到大厂高薪offer?
Difference between redo and undo
今日群里分享的面试题
解决VSCode下载慢或下载失败的问题