Thursday 21 May 2015

Vector Iterator Example

import java.util.Iterator;
import java.util.Vector;

public class IterateVector {

   
    public static void main(String[] args) {
      
        Vector<String> vector = new Vector<String>();
      
        //add element in vector
        vector.add("cricket");
        vector.add("hockey");
        vector.add("football");
        vector.add("tennish");
      
        //Returns an iterator over the elements in
        //this list in proper sequence.
        Iterator<String> itr = vector.iterator();
        while (itr.hasNext()) {
            System.out.println("element is = "+itr.next());
           
        }
      
    }
   
}


Output:

element is = cricket

element is = hockey

element is = football

element is = tennish


No comments:

Post a Comment