LinkedBlockingQueue toString() method in Java Last Updated : 18 Sep, 2018 Summarize Comments Improve Suggest changes Share Like Article Like Report The toString() method of LinkedBlockingQueue returns a string representation of this collection. The string representation consists of a list of the collection's elements in the order they are returned by its iterator, enclosed in square brackets ("[]"). The adjacent elements are separated by the characters ", " (comma and space). The elements are converted to strings as by String.valueOf(Object). Syntax: public String toString() Parameters: This method does not accept any parameters. Returns: This method returns a string representation of this collection. Below programs illustrate toString() method of LinkedBlockingQueue: Program 1: Java // Java Program Demonstrate toString() // method of LinkedBlockingQueue import java.util.concurrent.LinkedBlockingQueue; import java.util.*; public class GFG { public static void main(String[] args) { // create object of LinkedBlockingQueue LinkedBlockingQueue<Integer> LBQ = new LinkedBlockingQueue<Integer>(); // Add numbers to end of LinkedBlockingQueue LBQ.add(7855642); LBQ.add(35658786); LBQ.add(5278367); LBQ.add(74381793); // Print the queue System.out.println("Linked Blocking Queue: " + LBQ); System.out.println("Linked Blocking Queue in string " + LBQ.toString()); } } Output: Linked Blocking Queue: [7855642, 35658786, 5278367, 74381793] Linked Blocking Queue in string [7855642, 35658786, 5278367, 74381793] Program 2: Java // Java Program Demonstrate toString() // method of LinkedBlockingQueue import java.util.concurrent.LinkedBlockingQueue; import java.util.*; public class GFG { public static void main(String[] args) { // create object of LinkedBlockingQueue LinkedBlockingQueue<String> LBQ = new LinkedBlockingQueue<String>(); // Add numbers to end of LinkedBlockingQueue LBQ.add("gopal"); LBQ.add("gate"); LBQ.add("GRE"); LBQ.add("CAT"); // Print the queue System.out.println("Linked Blocking Queue: " + LBQ); System.out.println("Linked Blocking Queue in string " + LBQ.toString()); } } Output: Linked Blocking Queue: [gopal, gate, GRE, CAT] Linked Blocking Queue in string [gopal, gate, GRE, CAT] Reference: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/LinkedBlockingQueue.html#toString-- Comment More infoAdvertise with us Next Article LinkedBlockingQueue toString() Method in Java with Examples G gopaldave Follow Improve Article Tags : Misc Java Java-Collections Java - util package Java-Functions Java-LinkedBlockingQueue +2 More Practice Tags : JavaJava-CollectionsMisc Similar Reads LinkedBlockingDeque toString() method in Java The toString() method of LinkedBlockingDeque returns a string representation of this collection. The string representation consists of a list of the collection's elements in the order they are returned by its iterator, enclosed in square brackets ("[]"). The adjacent elements are separated by the ch 2 min read LinkedBlockingQueue size() method in Java The size() method of LinkedBlockingQueue returns the number of elements that LinkedBlockingQueue contains. When queue is empty queue, size() returns 0 and when queue is full then size() returns the capacity of queue.Syntax: public int size() Return Value: This method returns the number of elements i 4 min read LinkedBlockingQueue toArray() method in Java toArray() The toArray method of LinkedBlockingQueue is used to create an array having the same elements as that of this LinkedBlockingQueue, in proper sequence. Actually, this method copies all the elements from the LinkedBlockingQueue to a new array. This method behaves as a bridge between array an 5 min read LinkedBlockingQueue | offer() Method in JAVA There is two types of offer() method for LinkedBlockingQueue class : offer(E e, long timeout, TimeUnit unit) The offer(E e, long timeout, TimeUnit unit) method of LinkedBlockingQueue inserts the element passed as parameter to method at the tail of this LinkedBlockingQueue if queue is not full. It wi 6 min read LinkedBlockingQueue toString() Method in Java with Examples The toString() method of LinkedBlockingQueue returns a String representation of the elements of LinkedBlockingQueue. The string of LinkedBlockingQueue contains its elements from first(head) to last(tail), enclosed in square brackets(â[]â) in proper order. The elements are separated by the characters 2 min read LinkedBlockingQueue remove() method in Java The remove(Object obj) method of LinkedBlockingQueue removes only one instance of the given Object, passed as parameter, from this LinkedBlockingQueue if it is present. It removes an element e such that obj.equals(e) and if this queue contains one or more instance of element e. This method returns t 4 min read Like