您可以使用
subList(int fromIndex, int toIndex)获取原始列表的一部分的视图。
从API:
Returns a view of the portion of this list between the specified fromIndex, inclusive, and toIndex, exclusive. (If fromIndex and toIndex are equal, the returned list is empty.) The returned list is backed by this list, so non-structural changes in the returned list are reflected in this list, and vice-versa. The returned list supports all of the optional list operations supported by this list.
例:
List numbers = new ArrayList(
Arrays.asList(5,3,1,2,9,5,0,7)
);
List head = numbers.subList(0, 4);
List tail = numbers.subList(4, 8);
System.out.println(head); // prints “[5, 3, 1, 2]”
System.out.println(tail); // prints “[9, 5, 0, 7]”
Collections.sort(head);
System.out.println(numbers); // prints “[1, 2, 3, 5, 9, 5, 0, 7]”
t