当前位置:网站首页>List中subList的add造成的死循环
List中subList的add造成的死循环
2022-06-23 22:12:00 【至学者】
一 代码示例
使用List中subList中的add方法添加数据:
public static void main(String[] args) {
List<Integer> integers = new ArrayList<>();
integers.add(1);
integers.add(2);
integers.add(3);
integers.add(4);
integers.add(5);
integers.add(6);
System.out.println("list的初始长度:" + integers.size());
List<Integer> list = integers.subList(0, 1);
for (int i = 0; i < integers.size(); i++) {
list.add(integers.get(i) + 1);
System.out.println("list增加长度:" + integers.size());
}
}二 结果及结果分析

通过debug运行循环两次,发现原来的List会随着subList的add添加数据一直增加长度,所以这回导致死循环的逻辑
三 源码分析
后续补充。。。
边栏推荐
- Autofac详解
- Bilibili × Blue bridge cloud course | online programming practice competition is new!
- ARouter 组件之间跳转需免混淆
- The sandbox week is coming!
- 巨头下场“摆摊”,大排档陷入“苦战”
- Graph theory (tree diameter)
- The Sandbox 与 BAYZ 达成合作,共同带动巴西的元宇宙发展
- [observation] Dell technology + Intel aoteng Technology: leading storage innovation with "nanosecond speed"
- 开发协同,高效管理 | 社区征文
- Detailed explanation of MySQL database configuration information viewing and modification methods
猜你喜欢

The Sandbox 与 BAYZ 达成合作,共同带动巴西的元宇宙发展

HDLBits-&gt;Circuits-&gt;Arithmetic Circuitd-&gt;3-bit binary adder

Graph theory (tree diameter)

谈谈数字化转型晓知识

Practice of issuing vouchers for Tiktok payment of 100000 TPS traffic

MySQL索引底层为什么用B+树?看完这篇文章,轻松应对面试。

Analysis on the advantages and disadvantages of the best 12 project management systems at home and abroad

【观察】戴尔科技+英特尔傲腾技术:以“纳秒之速”领跑存储创新
Androidkotlin comprehensive and detailed class usage grammar learning guide
Trigger definition and syntax introduction in MySQL
随机推荐
The national post office and other three departments: strengthen the security management of personal information related to postal express delivery, and promote the de identification technology of per
2022年信息安全工程师考试知识点:访问控制
What is the development prospect of face recognition technology?
短视频挺进在线音乐腹地
Practice of issuing vouchers for Tiktok payment of 100000 TPS traffic
TDD开发模式流程推荐
The sandbox and bayz have reached cooperation to jointly drive the development of metauniverse in Brazil
Fabric. JS manual bold text iText
"Shanda Diwei Cup" the 12th Shandong ICPC undergraduate program design competition
Ambire 指南:Arbitrum 奥德赛活动开始!第一周——跨链桥
小程序容器到底是什么
Can postman be integrated into Ci and CD pipelines for automated interface testing?
Kotlin 集合List 、Set、Map操作汇总
数据解读!理想L9冲刺「月销过万」,从BBA手中抢份额
Isolement des transactions MySQL
云原生流水线工具汇总
Kotlin coroutine asynchronous flow
Kotlin set list, set, map operation summary
Summary of some indicators for evaluating and selecting the best learning model
NLog details