Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Lines changed: 6 additions & 1 deletion
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)

AltStyle によって変換されたページ (->オリジナル) /