Printing the stack values in Java

后端 未结 8 1668
小蘑菇
小蘑菇 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:30

    stack.forEach(System.out::println);
    

    Using Java 8 and later stream functions

提交回复
热议问题