Friday 9 May 2014

Vector : removeElement : Removes Element

public synchronized boolean removeElement(Object obj)
Removes the first occurrence of the argument from this vector. return true if the argument was a component of this vector, else return false.

import java.util.*;

class VectorRemoveElement{
 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(10);
  myVector.add(10);
  
  System.out.println("Elements in myVector ");
  System.out.println(myVector);
  
  System.out.println("\nRemove First occurrence of 10");
  myVector.removeElement(10);
  System.out.println("Elements in myVector ");
  System.out.println(myVector); 
  
  System.out.println("\nRemove First occurrence of 10");
  myVector.removeElement(10);
  System.out.println("Elements in myVector ");
  System.out.println(myVector); 
 }
}

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

Remove First occurrence of 10
Elements in myVector
[11, 12, 10, 10]

Remove First occurrence of 10
Elements in myVector
[11, 12, 10]

Prevoius                                                 Next                                                 Home

No comments:

Post a Comment