Java Collections Java Java API
java.util.PriorityQueue
public E poll()
Retrieves and removes the head of this queue, or returns null if this queue is empty.
null
package com.logicbig.example.priorityqueue;import java.util.PriorityQueue;public class PollExample { public static void main(String... args) { PriorityQueue<String> pq = new PriorityQueue<>(); pq.offer("one"); pq.offer("two"); System.out.println(pq); String element = pq.poll(); System.out.println(element); element = pq.poll(); System.out.println(element); element = pq.poll(); System.out.println(element); }}
[one, two]onetwonull