Prev Next

Java / Queue and its implementations

1. Difference between offer and add method in priority queue in java.

The add() will throw an IllegalStateException if no space is currently available in the Queue otherwise add method will return true. offer() method will return false if the element cannot be inserted due to capacity restrictions.

Read full answer

2. List few Queue implementations.

LinkedList, ArrayDeque, PriorityQueue, and BlockingQueue types such as ArrayBlockingQueue implement Queue. ArrayDeque is the usual non-concurrent default.

Read full answer

3. Explain priority queue in Java.

An unbounded priority queue based on a priority heap . The elements of the priority queue are ordered according to their natural ordering, or using a Comparator provided at queue construction time, depending on which constructor is used....

Read full answer

4. Difference between PriorityQueue and TreeSet in Java.

PriorityQueue is a Queue and it provides the functionality of FIFO data structure, while TreeSet is a Set. TreeSet is a Set that doesn't allow duplicate elements but PriorityQueue may contain duplicates....

Read full answer

«
»

Comments & Discussions