Java Program to Change the Size of a Vector Collection

Java program to change the size of a Vector collection

// Java program to change the size of a 
// 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.setSize(7);

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

Output

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