Skip to content

Commit e4db572

Browse files
committed
Added another approach for max value in stream
1 parent d7899c3 commit e4db572

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/main/java/com/rampatra/java8/Streams.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,15 @@ public static Integer[] getAllTransValuesFromTradersInCambridge() {
123123
}
124124

125125
public static int findHighestTransactionValue() {
126+
return transactions.stream()
127+
.mapToInt(Transaction::getValue)
128+
.max().getAsInt();
129+
130+
/* this is another solution
126131
return transactions.stream()
127132
.map(Transaction::getValue)
128133
.reduce((t1, t2) -> (t1 > t2) ? t1 : t2) // you can replace with .reduce(Integer::max)
129-
.get();
134+
.get();*/
130135
}
131136

132137
public static Transaction getSmallestTransaction() {

0 commit comments

Comments
 (0)