Java Vector clear() Method

The clear() method of Java Vector class is used to remove all of the elements from the vector which is in use.

Syntax:

Following is the declaration of clear() method:

Parameter:

This method does not accept any parameter.

Returns:

This method has return type void so, it does not return any value.

Exceptions:

NA

Compatibility Version:

Java 1.2 and above

Example 1:

Test it Now

Output:

Size of Vector before clear() method: 3
Size of Vector after clear() method: 0

Example 2:

Test it Now

Output:

Elements of Vector is: [3, 5, 2, 4, 1]
Elements of Vector after clear(): []

Next TopicJava Vector




Latest Courses