Java Program to Set an Element at the Specified Index in Vector Collection

Java program to set an element at the specified index in Vector collection

// Java program to set an element at the 
// specified index in Vector collection

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(20);
    vec.add(12);

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

    vec.setElementAt(50, 2);

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

Output

Vector elements: [10, 20, 30, 20, 12]
Vector elements: [10, 20, 50, 20, 12]
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