ArrayBlockingQueue toString() Method in Java
The toString() method of ArrayBlockingQueue class is used to get a string representation of the objects of ArrayBlockingQueue. The string of ArrayBlockingQueue contains elements of ArrayBlockingQueue in the order from first(head) to last(tail), enclosed in square brackets(“”). The elements are separated by the characters”, ” (comma and a space). So basically the toString() method is used to convert all the elements of ArrayBlockingQueue into a String.
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.
public String toString()
Return Value: The method returns an String representation of ArrayBlockingQueue.
Below programs illustrates toString() method of ArrayBlockingQueue class:
Queue is [423, 422, 421, 420, 424] The String returned by toString(): [423, 422, 421, 420, 424]
Queue is [User, Employee, Manager, Analyst, HR, Tester] The String returned by toString(): [User, Employee, Manager, Analyst, HR, Tester]