java.util.Vector.subList() 方法
描述
subList(int fromIndex,int toIndex) 方法用于返回此列表在 fromIndex(包括)和 toIndex(不包括)之间部分的视图。 返回的 List 由此 List 支持,因此返回 List 中的更改会反映在此 List 中,反之亦然。
声明
以下是 java.util.Vector.subList() 方法的声明
public ListsubList(int fromIndex,int toIndex)
参数
fromIndex − 这是 subList 的低端点(包括)。
toIndex − 这是子列表的高端(不包括)。
返回值
方法调用返回此列表中指定范围的视图。
异常
IndexOutOfBoundsException − 如果端点索引值超出范围,则会抛出此错误
IllegalArgumentException − 如果端点索引无序,则会抛出此错误
示例
下面的例子展示了 java.util.Vector.subList() 方法的使用。
package com.tutorialspoint;
import java.util.*;
public class VectorDemo {
public static void main(String[] args) {
// create an empty Vector vec with an initial capacity of 4
Vector<Integer> vec = new Vector<Integer>(8);
List sublist = new ArrayList(10);
// use add() method to add elements in the vector
vec.add(4);
vec.add(3);
vec.add(2);
vec.add(1);
vec.add(6);
vec.add(7);
vec.add(9);
vec.add(5);
// lets make a sublist
sublist = vec.subList(2,6);
// let us print the size of the vector
System.out.println("Let us print the list: "+sublist);
}
}
让我们编译并运行上面的程序,这将产生以下结果.
Let us print the list: [2, 1, 6, 7]

