clear(): This method is available in java.util.Vector class of Java.
Syntax:
void java.util.Vector.clear()
This method removes all of the elements from this Vector. The Vector will be empty after this call returns.
Parameters: NA
Returns: NA
Exceptions: NA
Approach
Java
import java.util.Vector;public class Vectorclear {public static void main(String[] args) {Vector<String> vector = new Vector<>();vector.add("Hello");vector.add("Java");vector.add("C++");vector.add("Program");vector.clear();System.out.println(vector);}}
Output:
[]
No comments:
Post a Comment