Saturday 12 April 2014

iterator : Iterate in proper sequence

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

import java.util.*;
import java.util.concurrent.LinkedBlockingDeque;

class DequeIterate{
  public static void main(String args[]){
    Deque<Integer> myDeque = new LinkedBlockingDeque<Integer> (5);
  
  myDeque.add(10);
  myDeque.add(20);
  myDeque.add(30);
  myDeque.add(40);
  myDeque.add(10);
  
  Iterator<Integer> iter = myDeque.iterator();
  
  System.out.println("Elements in Deque are");
  while(iter.hasNext()){
  System.out.print(iter.next()+" ");
  }
 }
}

Output
Elements in Deque are
10 20 30 40 10


Prevoius                                                 Next                                                 Home

No comments:

Post a Comment