Java Program to Remove the First Occurrence of the Specified Element From Vector Collection

Java Program to Remove the First Occurrence of the Specified Element From Vector Collection

Java Program to Remove the First Occurrence of the Specified Element From Vector Collection

// Java program to remove the first occurrence of the 
// specified element from Vector collection

import java.util.*;

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

    vec.add("CAR");
    vec.add("BUS");
    vec.add("BIKE");
    vec.add("BUS");
    vec.add("TRUCK");

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

    vec.removeElement("BUS");
    System.out.println("Vector elements: " + vec);
  }
}
Vector elements: [CAR, BUS, BIKE, BUS, TRUCK]
Vector elements: [CAR, BIKE, BUS, TRUCK]

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

Share on:

Leave a Comment