In Java, I want to print the contents of a Stack. The toString()
method prints them encased in square brackets delimited by commas: [foo, bar, ba
Another method is the join
method of String which is similar to the join method of Python:
"" + String.join("/", stack)
This will return the string containing all the elements of the stack and we can also add some delimiter by passing in the first argument.
Example: Stack has two elements [home, abc]
Then this will return "/home/abc".