Home » Java Vector removeAll() Method with Examples

Java Vector removeAll() Method with Examples

by Online Tutorials Library

Java Vector removeAll() Method

The removeAll() method of Java Vector class deletes all the elements from the vector that are present in the specified collection.

Syntax

Following is the declaration of removeAll() method:

Parameter

Parameter Description Required/Optional
c It is a collection of elements which will be removed from the vector. Required

Return

The removeAll() method returns true if the vector changed as a result of the call.

Exceptions

NullPointerException– This method has thrown an exception if the vector contains one or more null elements and the specified collection does not support null elements or if the specified collection is null.

Compatibility Version

Java 1.2 and above

Example 1

Test it Now

Output:

Vector: [1, 2, 3, 4, 5]  Removing all the elements  Size of the vector: 0  

Example 2

Test it Now

Output:

Vector: [A, B, C, 10, 20]  Collection removed  Final Vector: [10, 20]  

Next TopicJava Vector

You may also like