Friday, 9 May 2014

Vector : removeAllElements : Remove All Elements

public synchronized void removeAllElements()
Removes all components from this vector and sets its size to zero.

import java.util.*;

class VectorRemoveAllClassCast{
 public static void main(String args[]){
  Vector<Integer> myVector;
  
  myVector = new Vector<> ();
  
  /*Add Elements to myVector*/
  myVector.add(10);
  myVector.add(11);
  myVector.add(12);
  myVector.add(13);
  myVector.add(14);
  
  System.out.println("Elements in myVector ");
  System.out.println(myVector);
  
  System.out.println("\nRemove All Elements");
  myVector.removeAllElements();
  
  System.out.println("\nElements in myVector ");
  System.out.println(myVector); 
 }
}

Output
Elements in myVector
[10, 11, 12, 13, 14]

Remove All Elements

Elements in myVector
[]


Prevoius                                                 Next                                                 Home

No comments:

Post a Comment