PriorityBlockingQueue toString() method in Java Last Updated : 11 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report The toString() method of PriorityBlockingQueue returns String representation of this PriorityBlockingQueue showing details of element contained by PriorityBlockingQueue. The string of PriorityBlockingQueue contains elements of PriorityBlockingQueue in the same order returned by its iterator, enclosed in square brackets(“[]”). The elements are separated by the characters ”, ” (comma and a space). So basically the toString() method is used to convert all the elements of PriorityBlockingQueue into a single String. Syntax: public String toString() Returns: This method returns a String representing the elements of this PriorityBlockingQueue. Below programs illustrate toString() method of PriorityBlockingQueue: Example 1: To demonstrate toString() method on PriorityBlockingQueue which contains a list of Integers. Java // Java Program Demonstrate toString() // method of PriorityBlockingQueue import java.util.concurrent.PriorityBlockingQueue; import java.util.*; public class GFG { public static void main(String[] args) throws InterruptedException { // create object of PriorityBlockingQueue PriorityBlockingQueue<Integer> PrioQueue = new PriorityBlockingQueue<Integer>(); // Add numbers to PriorityBlockingQueue PrioQueue.put(45815616); PrioQueue.put(4981561); PrioQueue.put(4594591); PrioQueue.put(9459156); // get String representation of PriorityBlockingQueue String str = PrioQueue.toString(); // print Details System.out.println("String representation: " + str); } } Output:String representation: [4594591, 9459156, 4981561, 45815616] Example 2: To demonstrate toString() method on PriorityBlockingQueue which contains list of Strings Java // Java Program Demonstrate toString() // method of PriorityBlockingQueue import java.util.concurrent.PriorityBlockingQueue; import java.util.*; public class GFG { public static void main(String[] args) throws InterruptedException { // create object of PriorityBlockingQueue // which contains Strings PriorityBlockingQueue<String> names = new PriorityBlockingQueue<String>(); // Add Strings names.add("Geeks"); names.add("forGeeks"); names.add("A Computer Portal"); names.add("By Sandeep Jain"); // get String representation of PriorityBlockingQueue String str = names.toString(); // print Details System.out.println("String representation: " + str); } } Output:String representation: [A Computer Portal, By Sandeep Jain, Geeks, forGeeks] Reference: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/PriorityBlockingQueue.html#toString-- Comment More infoAdvertise with us Next Article PriorityBlockingQueue size() method in Java A AmanSingh2210 Follow Improve Article Tags : Misc Java Java-Collections Java - util package Java-Functions Java-PriorityBlockingQueue +2 More Practice Tags : JavaJava-CollectionsMisc Similar Reads PriorityBlockingQueue size() method in Java The size() method of PriorityBlockingQueue is used to find the present size of the queue. It returns the number of elements in the collection. If the collection contains more than Integer.MAX_VALUE elements, then this method returns Integer.MAX_VALUE. Syntax: public int size() Return Value: This met 2 min read PriorityBlockingQueue size() method in Java The size() method of PriorityBlockingQueue is used to find the present size of the queue. It returns the number of elements in the collection. If the collection contains more than Integer.MAX_VALUE elements, then this method returns Integer.MAX_VALUE. Syntax: public int size() Return Value: This met 2 min read PriorityBlockingQueue toArray() method in Java toArray() The toArray method of PriorityBlockingQueue is used to create an array having the same elements as that of this PriorityBlockingQueue, in proper sequence. Actually, this method copies all the element from the PriorityBlockingQueue to a new array. This method behaves as a bridge between arr 4 min read PriorityBlockingQueue put() method in Java The put(E e) method of PriorityBlockingQueue is used to add an element into this queue. This method inserts the specified element into this priority queue. Since the queue is unbounded, this method will be never be blocked.Syntax: public void put(E e) Parameter: This method accepts a mandatory param 2 min read PriorityBlockingQueue put() method in Java The put(E e) method of PriorityBlockingQueue is used to add an element into this queue. This method inserts the specified element into this priority queue. Since the queue is unbounded, this method will be never be blocked.Syntax: public void put(E e) Parameter: This method accepts a mandatory param 2 min read PriorityBlockingQueue take() method in Java The take() method of PriorityBlockingQueue returns head of the queue after removing it. If queue is empty, then this method will wait until an element becomes available. Syntax: public E take() throws InterruptedException Returns: This method returns value at the head of this PriorityBlockingQueue. 2 min read Like