Thursday 8 May 2014

Vector : iterator : get the iterator

public synchronized Iterator<E> iterator()
Returns an iterator over the elements in this list in proper sequence.

import java.util.*;

class VectorIterator{
 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(12);
  
  Iterator<Integer> myIter = myVector.iterator();
  
  System.out.println("Elements in myVector are");
  while(myIter.hasNext()){
   System.out.println(myIter.next());
  }  
 }
}


Output
Elements in myVector are
10
11
12
10
12

Prevoius                                                 Next                                                 Home

No comments:

Post a Comment