Java Program to Remove All Elements of Vector Collection Contained in the Specified Collection

You are currently viewing Java Program to Remove All Elements of Vector Collection Contained in the Specified Collection

Java program to remove all elements of Vector collection contained in the specified collection

// Java program to remove all elements of Vector collection 
// contained in the specified collection

import java.util.*;

public class Main {
  public static void main(String[] args) {
    Vector vec1 = new Vector();
    Vector vec2 = new Vector();

    vec1.add(10);
    vec1.add(20.5);
    vec1.add(true);
    vec1.add("Hello World");

    vec2.add(10);
    vec2.add(true);

    System.out.println("Vector Vec1 : " + vec1);
    System.out.println("Vector Vec2 : " + vec2);

    vec1.removeAll(vec2);

    System.out.println("\nVector Vec1 : " + vec1);
    System.out.println("Vector Vec2 : " + vec2);
  }
}

Output

Vector Vec1 : [10, 20.5, true, Hello World]
Vector Vec2 : [10, true]

Vector Vec1 : [20.5, Hello World]
Vector Vec2 : [10, true]

Ranjith

Hi, I'm Manoj a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply