0 votes
1 view
in Java by (8.5k 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 (41.5k points)

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

System.out.println(Arrays.toString(stack.toArray()));

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...