2026/4/18 5:55:42
网站建设
项目流程
湖南做网站 n磐石网络,建网站用自己的主机做服务器,手机直播网站开发,初次创业开什么店合适subList(int fromIndex, int toIndex) 是 List 接口提供的视图操作#xff0c;用于在常数时间内获取原 List 的一个子列表。1、优点subList() 不复制数据#xff0c;而是基于原列表的视图#xff08;View#xff09;#xff0c;避免额外的内存开销2、底层实现subList() 不…subList(int fromIndex, int toIndex)是List接口提供的视图操作用于在常数时间内获取原List的一个子列表。1、优点subList()不复制数据而是基于原列表的视图View避免额外的内存开销2、底层实现subList()不会创建新的列表对象而是返回AbstractList#SubList视图它仅维护offset偏移量起始索引fromIndexsize子列表大小toIndex - fromIndex原List的引用子列表依赖原List进行操作ListInteger list new ArrayList(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));ListInteger subList list.subList(2, 6); // [3, 4, 5, 6]System.out.println(subList);subList.set(0, 99);System.out.println(list); // 原列表同步修改 - [1, 2, 99, 4, 5, 6, 7, 8, 9, 10]subList()不复制数据而是直接修改原List