File tree Expand file tree Collapse file tree 2 files changed +5
-5
lines changed
core-java-modules/core-java-collections-7/src
test/java/com/baeldung/printstack Expand file tree Collapse file tree 2 files changed +5
-5
lines changed Original file line number Diff line number Diff line change 22
33import java .util .ArrayDeque ;
44import java .util .ArrayList ;
5+ import java .util .Collections ;
56import java .util .Comparator ;
67import java .util .Deque ;
78import java .util .Iterator ;
@@ -42,13 +43,12 @@ public static void givenStack_whenUsingDirectForEach_thenPrintStack() {
4243
4344 public static void givenStack_whenUsingStreamReverse_thenPrintStack () {
4445 Stack <Integer > stack = new Stack <>();
45- stack .push (10 );
4646 stack .push (20 );
47+ stack .push (10 );
4748 stack .push (30 );
4849
49- stack .stream ()
50- .sorted (Comparator .reverseOrder ())
51- .forEach (System .out ::println );
50+ Collections .reverse (stack );
51+ stack .forEach (System .out ::println );
5252 }
5353
5454 public static void givenStack_whenUsingIterator_thenPrintStack () {
Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ void givenStack_whenUsingDirectForEach_thenPrintStack() throws Exception {
3030 @ Test
3131 void givenStack_whenUsingStreamReverse_thenPrintStack () throws Exception {
3232 String output = tapSystemOut (() -> PrintStack .givenStack_whenUsingStreamReverse_thenPrintStack ());
33- assertEquals ("30\n 20 \ n 10\n " , output .replace ("\r \n " , "\n " ));
33+ assertEquals ("30\n 10\n 20 \n " , output .replace ("\r \n " , "\n " ));
3434 }
3535
3636 @ Test
You can’t perform that action at this time.
0 commit comments