Java Program to Remove Elements From Vector Collection Based on a Specified Predicate

Java program to remove elements from Vector collection based on a specified predicate

// Java program to remove elements from Vector collection 
// based on a specified predicate

import java.util.*;

public class Main {
  public static void main(String[] args) {
    Vector < Integer > vec = new Vector < Integer > ();

    vec.add(10);
    vec.add(20);
    vec.add(30);
    vec.add(11);
    vec.add(12);

    System.out.println("Vector elements: " + vec);

    vec.removeIf(val -> (val >= 20));

    System.out.println("Vector elements: " + vec);
  }
}

Output

Set elements: [1, 2, 3, 4, 5, 6]
Items removed successfully.
Set elements: [1, 2, 3]
Share on:

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

Leave a Comment