Vector clear() Method in Java Last Updated : 12 Dec, 2024 Comments Improve Suggest changes Like Article Like Report The Java.util.Vector.clear() method is used to remove all the elements from a Vector. Using the clear() method only clears all the element from the vector and does not delete the vector. In other words, we can say that the clear() method is used to only empty an existing vector. Syntax:Vector.clear()Parameters: The method does not take any parameter Return Value: The function does not returns any value. Example of Vector clear() MethodBelow programs illustrate the Java.util.Vector.clear() method. Example 1: Java // Using Vector clear() Method import java.util.*; public class GFG { public static void main(String args[]) { // creating an empty Vector Vector<String> v = new Vector<String>(); // add elements in vector v.add("Welcome"); v.add("To"); v.add("GFG"); // displaying the Vector System.out.println("Elements in Vector : " + v); // clearing the vector elements v.clear(); // display vector after operation System.out.println("Vector after Operation : " + v); } } OutputElements in Vector : [Welcome, To, GFG] Vector after Operation : [] Example 2: Java // Using vector clear() Method import java.util.*; public class GFG { public static void main(String args[]) { // creating an empty Vector Vector<Integer> v = new Vector<Integer>(); // adding elements in vector v.add(10); v.add(15); v.add(30); // displaying the Vector System.out.println("Vector: " + v); // clearing vctor v.clear(); // display vector after operation System.out.println("The final Vector: " + v); } } OutputVector: [10, 15, 30] The final Vector: [] Comment More infoAdvertise with us K kundankumarjha Follow Improve Article Tags : Misc Java Java-Collections Java - util package Java-Functions Java-Vector +2 More Practice Tags : JavaJava-CollectionsMisc Explore BasicsIntroduction to Java4 min readJava Programming Basics9 min readJava Methods7 min readAccess Modifiers in Java6 min readArrays in Java9 min readJava Strings8 min readRegular Expressions in Java7 min readOOPs & InterfacesClasses and Objects in Java10 min readJava Constructors10 min readJava OOP(Object Oriented Programming) Concepts10 min readJava Packages7 min readJava Interface11 min readCollectionsCollections in Java12 min readCollections Class in Java13 min readCollection Interface in Java6 min readIterator in Java5 min readJava Comparator Interface6 min readException HandlingJava Exception Handling8 min readJava Try Catch Block4 min readJava final, finally and finalize4 min readChained Exceptions in Java3 min readNull Pointer Exception in Java5 min readException Handling with Method Overriding in Java4 min readJava AdvancedJava Multithreading Tutorial15+ min readSynchronization in Java10 min readFile Handling in Java5 min readJava Method References9 min readJava 8 Stream Tutorial15+ min readJava Networking15+ min readJDBC Tutorial12 min readJava Memory Management4 min readGarbage Collection in Java6 min readMemory Leaks in Java3 min readPractice JavaJava Interview Questions and Answers15+ min readJava Programs - Java Programming Examples8 min readJava Exercises - Basic to Advanced Java Practice Programs with Solutions7 min readJava Quiz | Level Up Your Java Skills1 min readTop 50 Java Project Ideas For Beginners and Advanced [Update 2025]15+ min read Like