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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。