Set size of Vector - Java Collection Framework

Java examples for Collection Framework:Vector

Description

Set size of Vector

Demo Code


import java.util.Vector;
 
public class Main {
 
  public static void main(String[] args) {
    Vector v = new Vector();
   /*  www.  ja va2 s  . c o m*/
    v.add("1");
    v.add("2");
    v.add("3");
    v.add("4");
    v.add("5");

    v.setSize(3);
   
    System.out.println("Vector elements after setting size to 3");
    for(int index=0; index < v.size(); index++)
      System.out.println(v.get(index));
   
    v.setSize(5);
 
    System.out.println("Vector elements after setting size to 5");
    for(int index=0; index < v.size(); index++)
      System.out.println(v.get(index));
   
  }
}

Result


Related Tutorials