Explore Courses Blog Tutorials Interview Questions
0 votes
in Java by (10.2k points)
I wish to print a Stack<Integer> object as nicely as the Eclipse debugger does (i.e. [1,2,3...]) but printing it with out = "output:" + stack doesn't return this nice result.

Just to clarify, I'm talking about Java's built-in collection so I can't override its toString().

How can I get a nice printable version of the stack?

1 Answer

0 votes
by (46k points)

You could convert it to an array and then print that out with Arrays.toString(Object[]):


Browse Categories