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 2
2
3
3
import java .util .ArrayDeque ;
4
4
import java .util .ArrayList ;
5
+ import java .util .Collections ;
5
6
import java .util .Comparator ;
6
7
import java .util .Deque ;
7
8
import java .util .Iterator ;
@@ -42,13 +43,12 @@ public static void givenStack_whenUsingDirectForEach_thenPrintStack() {
42
43
43
44
public static void givenStack_whenUsingStreamReverse_thenPrintStack () {
44
45
Stack <Integer > stack = new Stack <>();
45
- stack .push (10 );
46
46
stack .push (20 );
47
+ stack .push (10 );
47
48
stack .push (30 );
48
49
49
- stack .stream ()
50
- .sorted (Comparator .reverseOrder ())
51
- .forEach (System .out ::println );
50
+ Collections .reverse (stack );
51
+ stack .forEach (System .out ::println );
52
52
}
53
53
54
54
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 {
30
30
@ Test
31
31
void givenStack_whenUsingStreamReverse_thenPrintStack () throws Exception {
32
32
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 " ));
34
34
}
35
35
36
36
@ Test
You can’t perform that action at this time.
0 commit comments