Get Size of Vector and loop through the elements - Java Collection Framework

Java examples for Collection Framework:Vector

Description

Get Size of Vector and loop through the elements

Demo Code


import java.util.Vector;
 
public class Main {
 
  public static void main(String[] args) {
    Vector v = new Vector();
   /*from   w  w w.  j  a va  2 s .  co  m*/
    v.add("1");
    v.add("2");
    v.add("3");
 
    //To get size of Java Vector use int size() method
    int totalElements = v.size();
   
    System.out.println("Vector contains...");

    for(int index=0; index < totalElements; index++)
      System.out.println(v.get(index));
   
  }
}

Result


Related Tutorials