Tuesday, 6 May 2014

Vector : clear : Remove all Elements

public void clear()
Removes all of the elements from this Vector. 

import java.util.*;

class VectorClear{
 public static void main(String args[]){
  Vector<Integer> myVector;
  myVector = new Vector<> ();
  
  /* Add Elements to myVector */
  for(int i=1; i < 6; i++)
   myVector.addElement(i);
   
  System.out.println("Elements in myVector are");
  System.out.println(myVector);
  
  System.out.println("\nCalling clear method");
  
  myVector.clear();
  
  System.out.println("\nElements in myVector are");
  System.out.println(myVector);
 }
}

Output
Elements in myVector are
[1, 2, 3, 4, 5]

Calling clear method

Elements in myVector are
[]

 
Prevoius                                                 Next                                                 Home

No comments:

Post a Comment