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 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 LinkedBlockingDeque:



Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java Program Demonstrate toString()
// method of LinkedBlockingDeque
  
import java.util.concurrent.LinkedBlockingDeque;
import java.util.*;
  
public class GFG {
    public static void main(String[] args)
  
    {
  
        // create object of LinkedBlockingDeque
        LinkedBlockingDeque<Integer> LBD
            = new LinkedBlockingDeque<Integer>();
  
        // Add numbers to end of LinkedBlockingDeque
        LBD.add(7855642);
        LBD.add(35658786);
        LBD.add(5278367);
        LBD.add(74381793);
  
        // Print the queue
        System.out.println("Linked Blocking Deque: " + LBD);
  
        System.out.println("LBD in string " + LBD.toString());
    }
}

chevron_right


Output:

Linked Blocking Deque: [7855642, 35658786, 5278367, 74381793]
LBD in string [7855642, 35658786, 5278367, 74381793]

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java Program Demonstrate toString()
// method of LinkedBlockingDeque
  
import java.util.concurrent.LinkedBlockingDeque;
import java.util.*;
  
public class GFG {
    public static void main(String[] args)
  
    {
  
        // create object of LinkedBlockingDeque
        LinkedBlockingDeque<String> LBD
            = new LinkedBlockingDeque<String>();
  
        // Add numbers to end of LinkedBlockingDeque
        LBD.add("geeks");
        LBD.add("sudo");
        LBD.add("gate");
        LBD.add("gopal");
  
        // Print the queue
        System.out.println("Linked Blocking Deque: " + LBD);
  
        System.out.println("LBD in string " + LBD.toString());
    }
}

chevron_right


Output:

Linked Blocking Deque: [geeks, sudo, gate, gopal]
LBD in string [geeks, sudo, gate, gopal]

Reference: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/LinkedBlockingDeque.html#toString–

Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.