LinkedBlockingQueue toString() method in Java
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 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()); } } |
Linked Blocking Queue: [7855642, 35658786, 5278367, 74381793] Linked Blocking Queue in string [7855642, 35658786, 5278367, 74381793]
Program 2:
// 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()); } } |
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–
Recommended Posts:
- LinkedBlockingQueue toString() Method in Java with Examples
- LinkedBlockingQueue contains() method in Java
- LinkedBlockingQueue size() method in Java
- LinkedBlockingQueue take() Method in Java with Examples
- LinkedBlockingQueue clear() method in Java
- LinkedBlockingQueue iterator() method in Java
- LinkedBlockingQueue put() method in Java with Examples
- LinkedBlockingQueue peek() method in Java
- LinkedBlockingQueue remainingCapacity() method in Java
- LinkedBlockingQueue remove() method in Java
- LinkedBlockingQueue drainTo() method in Java
- LinkedBlockingQueue toArray() method in Java
- LinkedBlockingQueue | offer() Method in JAVA
- LinkedBlockingQueue poll() method in Java
- Java 8 | LinkedBlockingQueue spliterator() method with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



