当前位置:网站首页>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 to configure webrtc video streaming format for easygbs, a new version of national standard gb28181 video platform?
- [untitled]
- 【无标题】
- DTD modeling
- SQL 入门计划-1-选择
- Brpc understanding
- Actual combat of flutter - fast implementation of audio and video call application
- ModSim基本使用(Modbus模拟器)
- 有意思了!数据库也搞Serverless!
- SIP protocol of gb28181
猜你喜欢

1592 例题1 国王(Sgu223 LOJ10170 LUOGU1896 提高+/省选-) 暴力思考 状压DP 01背包

解决VSCode下载慢或下载失败的问题

Review the collection container again

GaussDB(for MySQL) :Partial Result Cache,通过缓存中间结果对算子进行加速

Why must we move from Devops to bizdevops?

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

今日群里分享的面试题

Why has instagram changed from a content sharing platform to a marketing tool? How do independent sellers use this tool?

HLS4ML报错The board_part definition was not found for tul.com.tw:pynq-z2:part0:1.0.
![[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
随机推荐
Anaconda installs the virtual environment to the specified path
Use the uni app demo provided by Huanxin to quickly realize one-on-one chat
一个悄然崛起的国产软件,低调又强大!
[SQL optimization] the difference between with as and temporary tables
JS 之 常用内置类的使用
MySQL reports an error can't create table 'demo01 tb_ Student‘ (errno: 150)*
Wireshark packet analysis TCP, FTP
安装sharp报错
Source code series of authentic children -inheritablethreadlocal (line by line source code takes you to analyze the author's ideas)
mysql 报错 Can‘t create table ‘demo01.tb_Student‘ (errno: 150)*
Using win7 vulnerability to crack the system login password
Optaplanner learning notes (I) case cloud balance
P2433 【深基1-2】小学数学 N 合一
servlet知识点
振弦采集模块测量振弦传感器的流程步骤
DDR4 test-2
Botu V16 obtains the system time and converts it into a string
Axure does not display catalogs
Audio and video, encoding and decoding related e-books, gadgets, packaged for free!
Review the collection container again