Inserts the specified element into this priority queue. As PriorityQueue
is not a capacity-restricted queue, this method always returns true.
PriorityQueue does not allow null elements:
package com.logicbig.example.priorityqueue;
import java.util.PriorityQueue;
public class OfferExample2 {
public static void main(String... args) {
PriorityQueue<String> pq = new PriorityQueue<>();
pq.offer(null);
}
}
Output
Caused by: java.lang.NullPointerException
at java.base/java.util.PriorityQueue.offer(PriorityQueue.java:337)
at com.logicbig.example.priorityqueue.OfferExample2.main(OfferExample2.java:15)
... 6 more