当前位置:网站首页>List remove an element
List remove an element
2022-04-23 04:43:00 【Mount MONI】
public static void main(String[] args) {
List<Map<String,Object>> list = new ArrayList<>(16);
for (int i = 0; i < 10; i++) {
Map<String, Object> map = new HashMap<>(16);
map.put(String.valueOf(i), CommonUtils.getRandomStr(10, 2));
list.add(map);
}
System.out.println(CommonUtils.toJSONStringContainNullValue(list));
for (int i = list.size()-1; i >=0 ; i--) {
if (list.get(i).containsKey("6")) {
list.remove(i);
}
}
System.out.println(CommonUtils.toJSONStringContainNullValue(list));
Iterator<Map<String,Object>> it = list.iterator();
while (it.hasNext()) {
boolean containsKey = it.next().containsKey("1");
if (containsKey) {
it.remove();
}
}
System.out.println(CommonUtils.toJSONStringContainNullValue(list));
for (int i = 0; i < list.size(); i++) {
if (list.get(i).containsKey("4")) {
list.remove(i--);
}
}
System.out.println(CommonUtils.toJSONStringContainNullValue(list));
}
Output results :
[{"0":"mQMmxEaGpp"},{"1":"hKQORyfYpO"},{"2":"FvyuTFTHFn"},{"3":"kJQcOFwZYy"},{"4":"lQKPiPDZST"},{"5":"fLQopHVlmP"},{"6":"ubFoVIuHlN"},{"7":"BotCiWFiCX"},{"8":"YNOUZavaBy"},{"9":"yBZGHuhfOo"}]
[{"0":"mQMmxEaGpp"},{"1":"hKQORyfYpO"},{"2":"FvyuTFTHFn"},{"3":"kJQcOFwZYy"},{"4":"lQKPiPDZST"},{"5":"fLQopHVlmP"},{"7":"BotCiWFiCX"},{"8":"YNOUZavaBy"},{"9":"yBZGHuhfOo"}]
[{"0":"mQMmxEaGpp"},{"2":"FvyuTFTHFn"},{"3":"kJQcOFwZYy"},{"4":"lQKPiPDZST"},{"5":"fLQopHVlmP"},{"7":"BotCiWFiCX"},{"8":"YNOUZavaBy"},{"9":"yBZGHuhfOo"}]
[{"0":"mQMmxEaGpp"},{"2":"FvyuTFTHFn"},{"3":"kJQcOFwZYy"},{"5":"fLQopHVlmP"},{"7":"BotCiWFiCX"},{"8":"YNOUZavaBy"},{"9":"yBZGHuhfOo"}]
版权声明
本文为[Mount MONI]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220558291645.html
边栏推荐
- La caméra Unity tourne avec la souris
- Case of using stream load to write data to Doris
- IEEE Transactions on systems, man, and Cybernetics: Notes for systems (TSMC)
- getprop 属性
- leetcode003--判断一个整数是否为回文数
- Brushless motor drive scheme based on Infineon MCU GTM module
- Chapter 4 - understanding standard equipment documents, filters and pipelines
- [paper reading] [3D object detection] voxel transformer for 3D object detection
- Last day of 2017
- Spark FAQ sorting - must see before interview
猜你喜欢
QML进阶(五)-通过粒子模拟系统实现各种炫酷的特效
用D435i录制自己的数据集运行ORBslam2并构建稠密点云
Go reflection rule
Record your own dataset with d435i, run orbslam2 and build a dense point cloud
那些年我面试过的Android开发岗总结(附面试题+答案解析)
Simply drag objects to the item bar
MySQL queries users logged in for at least N consecutive days
Use recyclerview to realize left-right side-by-side classification selection
[paper reading] [3D object detection] voxel transformer for 3D object detection
Apache Bench(ab 压力测试工具)的安装与使用
随机推荐
Migrate from MySQL database to AWS dynamodb
Flink case - Kafka, MySQL source
unity摄像机旋转带有滑动效果(自转)
重剑无锋,大巧不工
Programmers complain: I really can't live with a salary of 12000. Netizen: how can I say 3000
补充番外14:cmake实践项目笔记(未完待续4/22)
Small volume Schottky diode compatible with nsr20f30nxt5g
那些年我面试过的Android开发岗总结(附面试题+答案解析)
Summary of Android development posts I interviewed in those years (attached test questions + answer analysis)
leetcode002--将有符号整数的数字部分反转
The unity camera rotates with the mouse
Unity camera rotation with sliding effect (rotation)
test
383. 赎金信
简单的拖拽物体到物品栏
Error occurs when thymeleaf th: value is null
华为机试--高精度整数加法
Leetcode004 -- Roman numeral to integer
leetcode008--实现strStr()函数
Differences among electric drill, electric hammer and electric pick