当前位置:网站首页>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
边栏推荐
- New terminal play method: script guidance independent of technology stack
- What is the thirty-six plan
- Installation du compilateur croisé de la plateforme zynq
- Basic operation of sequence table
- General enumeration constant class
- Unity RawImage背景无缝连接移动
- 383. 赎金信
- 用D435i录制自己的数据集运行ORBslam2并构建稠密点云
- mysql table 中增加列的SQL语句
- MySQL time function query
猜你喜欢
[paper reading] [3D target detection] point transformer
Recommended scheme for national production of electronic components of wireless keyboard
How to regulate intestinal flora? Introduction to common natural substances, probiotics and prebiotics
[paper reading] [3D object detection] voxel transformer for 3D object detection
test
Programmers complain: I really can't live with a salary of 12000. Netizen: how can I say 3000
Ali's ten-year technical experts jointly created the "latest" jetpack compose project combat drill (with demo)
程序员抱怨:1万2的工资我真的活不下去了,网友:我3千咋说
zynq平臺交叉編譯器的安裝
Druid -- JDBC tool class case
随机推荐
Brushless motor drive scheme based on Infineon MCU GTM module
Leetcode005 -- delete duplicate elements in the array in place
getprop 属性
520. Detect capital letters
PIP3 installation requests Library - the most complete pit sorting
MySQL time function query
Unity camera rotation with sliding effect (rotation)
Eight misunderstandings that should be avoided in data visualization
Innovative practice of short video content understanding and generation technology in meituan
2021数学建模国赛一等奖经验总结与分享
用D435i录制自己的数据集运行ORBslam2并构建稠密点云
Luogu p1858 [multi person knapsack] (knapsack seeking the top k optimal solution)
KVM error: Failed to connect socket to ‘/var/run/libvirt/libvirt-sock‘
A lifetime of needs, team collaboration can play this way on cloud nailing applet
C language: spoof games
What's the difference between error and exception
解决ValueError: Argument must be a dense tensor: 0 - got shape [198602], but wanted [198602, 16].
Phishing for NFT
Logger and zap log Library in go language
Record the ThreadPoolExecutor main thread waiting for sub threads