Java Program to Remove a Specified Item From Vector Collection

You are currently viewing Java Program to Remove a Specified Item From Vector Collection

Java program to remove a specified item from Vector collection

// Java program to remove an item from 
// Vector collection

import java.util.*;

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

    vec.add(10);
    vec.add(20.5);
    vec.add(true);

    System.out.println("Vector Elements:");
    for (Object obj: vec) {
      System.out.println("  " + obj);
    }

    vec.remove(20.5);

    System.out.println("Updated Vector Elements:");
    for (Object obj: vec) {
      System.out.println("  " + obj);
    }
  }
}

Output

Vector Elements:
  10
  20.5
  true
Updated Vector Elements:
  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