当前位置:网站首页>判断两个集合的相同值 ||不同值
判断两个集合的相同值 ||不同值
2022-06-26 03:43:00 【丶强风吹拂】
取相同值
// 1 数据一
List<Integer> ces1 = Arrays.asList(2, 3, 454, 5, 3);
// 2 数据二
List<Integer> ces2 = Arrays.asList(2, 3, 43, 5, 32, 12);
// 存放结果
List list=new ArrayList();
// 创建一map集合 将数据一的值 当做k来存放
HashMap<Object,
Object> map = new HashMap<>();
//3 遍历测试一的值
for (Integer e :ces1) {
// 4存入map集合中
map.put(e, 1);
}
//5 遍历 测试数据2 与map的key 做比较 如果有map的k有测试数据的2的值 它会添加到list集合中
for (Integer a:ces2){
if (StringUtils.isNotBlank(Integer.toString(a))&& map.containsKey(a)){
list.add(a);
}
}
System.out.println(list);
}
不同值
只需要把 map.containsKey(a) 改为 !map.containsKey(a)

边栏推荐
- Comparison of static methods and variables with instance methods and variables
- Run multiple main functions in the clion project
- Add an "open search description" to the site to adapt to the browser's "site search"“
- Dynamic segment tree leetcode seven hundred and fifteen
- 用eclipse连mysql数据库出错然后出现图中的话是咋回事呀
- Uni app swiper rotation chart (full screen / card)
- 【好书集锦】从技术到产品
- mysql存储过程
- 816. 模糊坐标
- 开源!ViTAE模型再刷世界第一:COCO人体姿态估计新模型取得最高精度81.1AP
猜你喜欢

MySQL advanced part (IV: locking mechanism and SQL optimization)

ASP. Net startup and running mechanism

Todolist incomplete, completed

"Renegotiation" agreement

Alibaba cloud function computing service one click to build Z-blog personal blog

ABP framework Practice Series (III) - domain layer in depth

Uni app custom navigation bar component

After Ali failed to start his job in the interview, he was roast by the interviewer in the circle of friends (plug)

使用SOAPUI访问对应的esb工程

Digital twin intelligent water service, breaking through the development dilemma of sponge City
随机推荐
JS to achieve the effect of text marquee
优化——多目标规划
Contains an object field at offset position
763. dividing alphabetic intervals
Procédures stockées MySQL
Android gap animation translate, scale, alpha, rotate
Tupu software is the digital twin of offshore wind power, striving to be the first
Sqlitestudio download address
navicat16无线试用
MySQL addition, deletion, query and modification (Advanced)
【Appium踩坑】io.appium.uiautomator2.common.exceptions.InvalidArgumentException: ‘capabilities‘ are mand
WebRTC系列-网络传输之7-ICE补充之偏好(preference)与优先级(priority)
When the tiflash function is pushed down, it must be known that it will become a tiflash contributor in ten minutes
Optimization - multi objective planning
神经网络学习小记录71——Tensorflow2 使用Google Colab进行深度学习
redux-thunk 简单案例,优缺点和思考
Classic model – RESNET
【Flink】Flink源码分析——批处理模式JobGraph的创建
QPS的概念和实现
2022.6.25 - leetcode. Un doigt d'épée. 091.