描述
這個removeElementAt(int index)方法用於刪除指定索引處的組件。此向量中索引大於或等於指定索引的每個組件向下移動,使其索引比之前的值小 1,並且此向量的大小減 1。
聲明
以下是聲明java.util.Vector.removeElementAt()方法
public void removeElementAt(int index)
參數
index─ 這是要刪除的對象的索引。
返回值
NA
異常
ArrayIndexOutOfBoundsException- 如果索引無效,則拋出此異常。
示例
下麵的例子展示了 java.util.Vector.removeElementAt() 方法的用法。
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);
// lets remove element at index 2
System.out.println("Remove element at index 2");
vec.removeElementAt(2);
// let us print all the elements available in vector
System.out.println("Added numbers are:- ");
for (Integer number:vec) {
System.out.println("Number = " + number);
}
}
}
讓我們編譯並運行上麵的程序,這將產生以下結果。
Remove element at index 2 Added numbers are:- Number = 4 Number = 3 Number = 1
相關用法
- Java java.util.Vector.removeAll()用法及代碼示例
- Java java.util.Vector.removeAllElements()用法及代碼示例
- Java java.util.Vector.removeRange()用法及代碼示例
- Java java.util.Vector.remove()用法及代碼示例
- Java java.util.Vector.retainAll()用法及代碼示例
- Java java.util.Vector.indexOf()用法及代碼示例
- Java java.util.Vector.contains()用法及代碼示例
- Java java.util.Vector.size()用法及代碼示例
- Java java.util.Vector.addElement()用法及代碼示例
- Java java.util.Vector.ensureCapacity()用法及代碼示例
- Java java.util.Vector.get()用法及代碼示例
- Java java.util.Vector.lastIndexOf()用法及代碼示例
- Java java.util.Vector.subList()用法及代碼示例
- Java java.util.Vector.trimToSize()用法及代碼示例
- Java java.util.Vector.toArray()用法及代碼示例
- Java java.util.Vector.clone()用法及代碼示例
- Java java.util.Vector.capacity()用法及代碼示例
- Java java.util.Vector.firstElement()用法及代碼示例
- Java java.util.Vector.isEmpty()用法及代碼示例
- Java java.util.Vector.lastElement()用法及代碼示例
注:本文由純淨天空篩選整理自 java.util.Vector.removeElementAt() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。