E remove(int index)
描述 (Description)
remove(int index)方法用于删除此Vector中specified position的元素。它将任何后续元素移到左侧(从索引中减去一个)。它alserReturns从Vector中删除的元素。
声明 (Declaration)
以下是java.util.Vector.remove()方法的声明
public E remove(int index)
参数 (Parameters)
index - 这是要删除的元素的索引。
返回值 (Return Value)
方法调用返回已删除的元素。
异常 (Exception)
ArrayIndexOutOfBoundsException - 如果索引超出范围,则抛出此异常。
例子 (Example)
以下示例显示了java.util.Vector.remove()方法的用法。
package com.iowiki;
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