通过指定索引检索从一个ArrayList elemnts [英] Retrieving elemnts from an ArrayList by specifying the indexes
本文介绍了通过指定索引检索从一个ArrayList elemnts的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有在Java中的方法,从一个ArrayList获得对象列表到另一个ArrayList中,仅通过指定开始和结束索引?
Is there a method in Java to get the list of objects from an Arraylist to another ArrayList, by just specifying the start and end index?
推荐答案
是的,你可以使用<$c$c>subList$c$c>方法:
Yes you can use the subList
method:
List<...> list2 = list1.subList(startIndex, endIndex);
这将返回原始表的那部分视图,它不会复制数据。结果
如果你想要一个副本:
This returns a view on that part of the original list, it does not copy the data.
If you want a copy:
List<...> list2 = new ArrayList<...> (list1.subList(startIndex, endIndex));
这篇关于通过指定索引检索从一个ArrayList elemnts的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文