当前位置:网站首页>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添加数据一直增加长度,所以这回导致死循环的逻辑
三 源码分析
后续补充。。。
边栏推荐
- Zynq ultrascale+ RF data converter IP configuration - ADC
- Eight models of data analysis: detailed PEST model
- Talking about the knowledge of digital transformation
- 【设计】1359- Umi3 如何实现插件化架构
- 网站如何在Google建立索引
- HAOGE's blog Road
- Common core resource objects of kubernetes
- How to index websites in Google
- C# 读取内存条占用大小,硬盘占用大小
- 短视频挺进在线音乐腹地
猜你喜欢
随机推荐
[js] 去除小数点后面多余的零
Construction of cache stack FIFO in different application scenarios for PLC data operation series (detailed algorithm explanation)
远程办公之:如何成为时间管理大师?| 社区征文
How to connect the fortress machine to the new server? What can I do if there is a problem with the fortress machine?
图论(树的直径)
Stm32 - - - - interruption externe
微信视频号如何用 PC 电脑做直播?
MySQL事务隔离
MySQL导致索引失效的几种情况
Ambire 指南:Arbitrum 奥德赛活动开始!第一周——跨链桥
PHP timestamp
Activity的onSaveInstanceState回调时机
Summary of cloud native pipeline tools
MySQL索引底层为什么用B+树?看完这篇文章,轻松应对面试。
[observation] Dell technology + Intel aoteng Technology: leading storage innovation with "nanosecond speed"
NLog details
对不起,你的USB走线可能搞错了!
Detailed quaternion
HDLBits-&gt;Circuits-&gt;Arithmetic Circuitd-&gt;3-bit binary adder
【观察】戴尔科技+英特尔傲腾技术:以“纳秒之速”领跑存储创新









