VOOZH about

URL: https://www.geeksforgeeks.org/java/stack-tostring-method-in-java-with-example/

⇱ Stack toString() method in Java with Example - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Stack toString() method in Java with Example

Last Updated : 24 Dec, 2018
The toString() method of Java Stack is used to return a string representation of the elements of the Collection. The String representation comprises a set representation of the elements of the Collection in the order they are picked by the iterator closed in square brackets[].This method is used mainly to display collections other than String type(for instance: Object, Integer)in a String Representation. Syntax:
public String toString()
Parameter The method does not take any parameters. Return This method returns a String representation of the collection. Below examples illustrate the toString() method: Example 1:
Output:
[Welcome, To, Geeks, For, Geeks]
Example 2:
Output:
[10, 20, 30, 40]
Comment