Java Program to Get Element From Vector Collection at the Specified Index

You are currently viewing Java Program to Get Element From Vector Collection at the Specified Index

Java program to get element from Vector collection at the specified index

// Java program to get element from Vector collection 
// at the specified index

import java.util.*;

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

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

    System.out.println("Vector elements: " + vec);
    System.out.println("Element at index " + index + " is: " + vec.elementAt(index));
  }
}

Output

Vector elements: [CAR, BUS, BIKE, TRUCK]
Element at index 2 is: BIKE

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