VOOZH about

URL: https://www.geeksforgeeks.org/java/linkedblockingqueue-tostring-method-in-java-with-examples/

⇱ LinkedBlockingQueue toString() Method in Java with Examples - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

LinkedBlockingQueue toString() Method in Java with Examples

Last Updated : 26 Nov, 2018
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]
Output:
Queue Representation:
[Employee [name=Aman, position=Analyst, salary=24000], Employee [name=Sachin, position=Developer, salary=39000]]
Reference: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/LinkedBlockingQueue.html#toString--
Comment