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 ', ' (comma and a space). So basically the toString() method is used to convert all the elements of LinkedBlockingQueue into a String representation.
This method overrides the toString() in class
AbstractCollection<E>
Syntax:
public String toString()
Return Value: This method returns a String which is the representation of the elements of LinkedBlockingQueue from first(head) to last(tail), enclosed in square brackets(“[]”) in proper order,separated by the ', ' (comma and a space).
Below programs illustrates toString() method of LinkedBlockingQueue class:
Program 1:
Output:
Queue Representation:
[2300, 1322, 8945, 6512]