0% found this document useful (0 votes)
18 views3 pages

31 Dec 2024

The Queue Interface in Java is implemented by LinkedList and PriorityQueue, storing elements in FIFO order. Key methods include offer, poll, remove, and peek for managing queue elements. PriorityQueue does not maintain insertion order, returns elements in ascending order, does not accept null values, and allows duplicates with a default capacity of 11.

Uploaded by

kanti chandrakar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views3 pages

31 Dec 2024

The Queue Interface in Java is implemented by LinkedList and PriorityQueue, storing elements in FIFO order. Key methods include offer, poll, remove, and peek for managing queue elements. PriorityQueue does not maintain insertion order, returns elements in ascending order, does not accept null values, and allows duplicates with a default capacity of 11.

Uploaded by

kanti chandrakar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Queue Interface

 The implementation classes for Queue Interface are


LinkedList & PriorityQueue.
 In Queue elements are stored in FIFO order.

 If we are creating an object for LinkedList with


LinkedList reference variable, then we can access
complete functionality of Queue & List.
 From 1.5v onwards LinkedList also implements Queue
interface.
Queue Interface Methods
Method Description

Offer(Object o); Add an element in to Queue

To remove and return first element of the Queue (returns


Object poll() ; null if the queue is empty)

To remove and return first element of the Queue


Object remove(); (NoSuchElementException when the queue is empty)

Object peek(); To return first element of the Queue without removing it


PriorityQueue
 It doesn’t maintains insertion order and returns the elements in
ascending order (Smallest Number first).
 In PriorityQueue the top element is always the smallest
element.
 It doesn’t accept null.
 PriorityQueue is available since jdk1.5V.
 It allows duplicate values, default capacity is 11.
PriorityQueue q=new PriorityQueue();
PriorityQueue q=new PriorityQueue(int initialcapacity);

You might also like