Friday 7 November 2014

Java : Collection Framework : Queue (How to get elements)


Click here to watch in Youtube : https://www.youtube.com/watch?v=UVJnWV-sjSs

QueueExample.java
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Queue;

public class QueueExample
{

    public static void main( String[] args )
    {
        Queue<Integer> queue = new LinkedList<Integer>();
        queue.add(200);
        queue.add(300);
        queue.add(400);
        queue.add(500);

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

        Iterator<Integer> iterator = queue.iterator();
        /*
         * Using Iterator traverse the queue and get each element.
         */
        while( iterator.hasNext() )
        {
            Integer value = iterator.next();
            System.out.println(value);
        }

    }
}

Output
queue : [200, 300, 400, 500]

200
300
400
500

To Download QueueDemoGetAllelements Project Click the below link

https://sites.google.com/site/javaee4321/java-collections/QueueDemoGetAllelements.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