java.util.Vector.remove() 方法
描述
remove(int index) 方法用于移除此 Vector 中指定位置处的元素。它将所有后续元素向左移动(从它们的索引中减去一个) .它也r返回从Vector中移除的元素。
声明
以下是 java.util.Vector.remove() 方法的声明
public E remove(int index)
参数
index − 这是要删除的元素的索引。
返回值
方法调用返回被移除的元素。
异常
ArrayIndexOutOfBoundsException − 如果索引超出范围,则会引发此异常。
示例
下面的例子展示了 java.util.Vector.remove() 方法的使用。
package com.tutorialspoint;
import java.util.Vector;
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>(4);
// use add() method to add elements in the vector
vec.add(4);
vec.add(3);
vec.add(2);
vec.add(1);
// let us remove the 1st element
System.out.println("Removed element: "+vec.remove(1));
}
}
让我们编译并运行上面的程序,这将产生以下结果.
Removed element: 3

