Mega Code Archive

 
Categories / Java / Collections Data Structure
 

Removing the first item from the queue

import java.util.LinkedList; import java.util.Queue; public class Main {     public static void main(String[] args) {         Queue<String> queue = new LinkedList<String>();                  queue.add("A");         queue.add("B");                  queue.offer("C");         queue.offer("D");         System.out.println("remove: " + queue.remove());         System.out.println("element: " + queue.element());                  System.out.println("poll: " + queue.poll());         System.out.println("peek: " + queue.peek());     } } /* remove: A element: B poll: B peek: C */