If you have implemented the stack using the collections framework then just say thanks to streams :) stack.stream().forEach(System.out::println);
stack.stream().forEach(System.out::println);