Thursday 13 November 2014

Java : Collection Framework : Deque (How to get element using Iterator)


Click here to watch in Youtube :
https://www.youtube.com/watch?v=6M5lT7SpGnw&list=UUhwKlOVR041tngjerWxVccw

DequeExample.java
import java.util.Deque;
import java.util.Iterator;
import java.util.LinkedList;

/*
 *  Example of iterator() method.
 */
public class DequeExample
{

    public static void main(String[] args)
    {
        Deque<Integer> deque = new LinkedList<Integer>();
        deque.add(100);
        deque.add(200);
        deque.add(300);

        System.out.println("deque : " + deque + "\n");

        /*
         * Returns an iterator over the elements in this deque in proper
         * sequence. The elements will be returned in order from first (head) to
         * last (tail).
         */

        Iterator<Integer> iterator = deque.iterator();

        while (iterator.hasNext())
        {
            Integer value = iterator.next();
            System.out.println(value);
        }

    }
}

Output
deque : [100, 200, 300]

100
200
300

To Download DequeDemoIterator Project Click the below link

https://sites.google.com/site/javaee4321/java-collections/DequeDemoIterator.zip?attredirects=0&d=1

See also:

  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • No comments:

    Post a Comment