Printing the stack values in Java

后端 未结 8 1612
小蘑菇
小蘑菇 2021-01-11 12:40

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

8条回答
  •  情话喂你
    2021-01-11 13:24

    There is a workaround.

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

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

提交回复
热议问题