Java.util.Vector.removeAllElements()方法用於從此Vector中刪除所有組件,並將其大小設置為零。
用法:
Vector.removeAllElements()
參數:該方法不帶任何參數
返回值:該函數不返回任何值。
以下示例程序旨在說明Java.util.Vector.removeAllElements()方法。
示例1:
// Java code to illustrate removeAllElements()
import java.util.*;
public class GFG {
public static void main(String args[])
{
// Creating an empty Vector
Vector<String> vector = new Vector<String>();
// Use add() method to add elements into the Vector
vector.add("Welcome");
vector.add("To");
vector.add("Geeks");
vector.add("4");
vector.add("Geeks");
// Displaying the Vector
System.out.println("Vector: " + vector);
// removeAllElementsing the Vector
// using removeAllElements() method
vector.removeAllElements();
// Displaying the final Vector after removeAllElement
System.out.println("The final Vector: " + vector);
}
}
輸出:
Vector: [Welcome, To, Geeks, 4, Geeks] The final Vector: []
示例2:
// Java code to illustrate removeAllElements()
import java.util.*;
public class GFG {
public static void main(String args[])
{
// Creating an empty Vector
Vector<Integer> vector = new Vector<Integer>();
// Use add() method to add elements into the Queue
vector.add(10);
vector.add(15);
vector.add(30);
vector.add(20);
vector.add(5);
// Displaying the Vector
System.out.println("Vector: " + vector);
// removeAllElementsing the Vector
// using removeAllElements() method
vector.removeAllElements();
// Displaying the final Vector after removeAllElement
System.out.println("The final Vector: " + vector);
}
}
輸出:
Vector: [10, 15, 30, 20, 5] The final Vector: []
相關用法
- Java Stack removeAllElements()用法及代碼示例
- Java Vector set()用法及代碼示例
- Java Vector contains()用法及代碼示例
- Java Vector get()用法及代碼示例
- Java Vector add()用法及代碼示例
- Java Vector elements()用法及代碼示例
- Java Vector removeElement()用法及代碼示例
- Java Vector equals()用法及代碼示例
- Java Vector size()用法及代碼示例
- Java Vector ensureCapacity()用法及代碼示例
- Java Vector trimToSize()用法及代碼示例
- Java Vector setSize()用法及代碼示例
- Java Vector removeIf()用法及代碼示例
- Java Vector toString()用法及代碼示例
- Java Vector hashCode()用法及代碼示例
注:本文由純淨天空篩選整理自ankit15697大神的英文原創作品 Vector removeAllElements() method in Java with Example。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。