Home » Java programming language

Java Vector removeAll() Method with Example

Vector Class removeAll() method: Here, we are going to learn about the removeAll() method of Vector Class with its syntax and example.
Submitted by Preeti Jain, on March 19, 2020

Vector Class removeAll() method

  • removeAll() method is available in java.util package.
  • removeAll() method is used to remove all of the existing elements in the given collection of this Vector.
  • removeAll() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
  • removeAll() method may throw an exception at the time of removing existing elements.
    NullPointerException: This exception may throw when the given parameter is null exists.


    public boolean removeAll(Collection co);


  • Collection co – represents the Collection object that contain elements to be removed from this Vector.

Return value:

The return type of the method is boolean, it returns true when all elements of this Vector is to be removed that exists in the given collection otherwise it returns false.


// Java program to demonstrate the example 
// of boolean removeAll(Collection co)
// method of Vector 

import java.util.*;

public class RemoveAllOfVector {
 public static void main(String[] args) {
  // Instantiates a Vector object  with
  // initial capacity of "10"
  Vector < String > v = new Vector < String > (10);
  ArrayList arr_l = new ArrayList();

  // By using add() method is to add the
  // elements in this v

  // By using add() method is to add the
  // elements in this arr_l

  // Display Vector and ArrayList
  System.out.println("v: " + v);
  System.out.println("arr_l: " + arr_l);

  // By using removeAll(arr_l) method is to
  // remove all elements of this vector v that
  // exists in the given collection arr_l

  // Display updated Vector
  System.out.println("v.removeAll(arr_l): " + v);


v: [C, C++, JAVA]
arr_l: [C, C++, SFDC]
v.removeAll(arr_l): [JAVA]

Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.