当前位置:网站首页>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
边栏推荐
- KVM error: Failed to connect socket to ‘/var/run/libvirt/libvirt-sock‘
- Huawei machine test -- high precision integer addition
- Alibaba tip: it is better to create threads manually
- MySQL queries users logged in for at least N consecutive days
- Unity rawimage background seamlessly connected mobile
- 递归调用--排列的穷举
- Installation of zynq platform cross compiler
- MySQL time function query
- Inverse system of RC low pass filter
- QML进阶(五)-通过粒子模拟系统实现各种炫酷的特效
猜你喜欢

Improving 3D object detection with channel wise transformer

Recommended scheme for national production of electronic components for wireless charging

C language: spoof games

Spark FAQ sorting - must see before interview

QML advanced (IV) - drawing custom controls

QML advanced (V) - realize all kinds of cool special effects through particle simulation system

Apache Bench(ab 压力测试工具)的安装与使用

Installation and deployment of Flink and wordcount test

Inverse system of RC low pass filter

Teach you how to build the ruoyi system by Tencent cloud
随机推荐
Mysql, binlog log query
Gut liver axis: host microbiota interaction affects hepatocarcinogenesis
Error occurs when thymeleaf th: value is null
Unity RawImage背景无缝连接移动
Spark FAQ sorting - must see before interview
Shanghai Hangxin technology sharing 𞓜 overview of safety characteristics of acm32 MCU
Spark small case - RDD, broadcast
Migrate from MySQL database to AWS dynamodb
Unity camera rotation with sliding effect (rotation)
QML advanced (IV) - drawing custom controls
Summary of Android development posts I interviewed in those years (attached test questions + answer analysis)
Summary of MySQL de duplication methods
Coinbase:关于跨链桥的基础知识、事实和统计数据
Record the ThreadPoolExecutor main thread waiting for sub threads
Last day of 2017
Druid -- JDBC tool class case
2020 is coming to an end, special and unforgettable.
zynq平臺交叉編譯器的安裝
Detailed explanation of life cycle component of jetpack
win10, mysql-8.0.26-winx64.zip 安装