PriorityQueue class Methods in Java Part -II

java.util.PriorityQueue

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


Some methods of  PriorityQueue class.


peek(): This method retrieves, but does not remove, the head of this queue, or returns null if this queue is empty.


poll(): This method retrieves and removes the head of this queue, or returns null if this queue is empty.


remove(): This method retrieves and removes the head of this queue.


remove(Object): This method removes a single instance of the specified element from this queue if it is present.


removeAll(Collection): This method removes all of this collection's elements that are also contained in the specified collection.


removeIf(Predicate): This method removes all of the elements of this collection that satisfy the given predicate.


retainAll(Collection): This method retains only the elements in this collection that are contained in the specified collection


size(): This method returns the number of elements in this collection.


spliterator(): This method creates a late-binding and fail-fast Spliterator over the elements in this queue.


stream(): This method returns a sequential Stream with this collection as its source.


toArray(): This method returns an array containing all of the elements in this queue.


toArray(IntFunction):  This method returns an array containing all of the elements in this collection, using the provided generator function to allocate the returned array.


toArray(K[]): This method returns an array containing all of the elements in this queue; the runtime type of the returned array is that of the specified array.


toString(): This method returns a string representation of this collection.


Some more Methods of PriorityQueue class Methods


No comments:

Post a Comment