Queue via LinkedList or LinkedBlockingQueue - Java java.util.concurrent

Java examples for java.util.concurrent:LinkedBlockingQueue

Description

Queue via LinkedList or LinkedBlockingQueue

Demo Code


import java.util.LinkedList;
import java.util.Queue;
import java.util.concurrent.LinkedBlockingQueue;

public class Main {
  
  public static void main(String atrg[]){
    Queue<Integer> mq= new LinkedList<Integer>();
    //Other Collection that can be used
    //Queue<Integer> mq= new LinkedBlockingQueue();    
  
    mq.add(1);/*www . j a v a 2s .  co  m*/
    mq.add(8);
    mq.add(4);
    mq.add(7);
    System.out.println(mq);
    int first = mq.poll();  //retrieve and remove the first element
    
    System.out.println(first);
    mq.poll();
    mq.poll();
        
    System.out.println(mq);
    
  }

}

Related Tutorials