Friday 9 May 2014

Vector : size : Get number Of elements in vector

public synchronized int size()
Returns the number of components in this vector.

import java.util.*;

class VectorSize{
 public static void main(String args[]){
  Vector<Integer> myVector; 
  myVector = new Vector<> ();
  
  System.out.print("Size of Vector is ");
  System.out.println(myVector.size());
  
  /* Add Elements to myVector */
  myVector.add(10);
  myVector.add(20);
  
  System.out.print("Size of Vector is ");
  System.out.println(myVector.size());
 }
}

Output
Size of Vector is 0
Size of Vector is 2


Prevoius                                                 Next                                                 Home

No comments:

Post a Comment