Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Update PuttingIntoPractice.java
Added code for Query 8 mentioned in the book. Fetching min value from array uses MAX_VALUE.
Also, added Integer.MIN_VALUE instead of 0 as there could be negative values in the array and return value is always 0
  • Loading branch information
pkulkarni4 authored Sep 23, 2023
commit e4dd5ee359990775fad6dbafdc5320f09cb54b03
10 changes: 8 additions & 2 deletions src/main/java/lambdasinaction/chap5/PuttingIntoPractice.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,13 @@ public static void main(String ...args){
int highestValue =
transactions.stream()
.map(Transaction::getValue)
.reduce(0, Integer::max);
.reduce(Integer.MIN_VALUE, Integer::max);
System.out.println(highestValue);

//Query 8: Find the transaction with the smallest value.
int smallestValue = transactions.stream()
.map(Transaction::getValue)
.reduce(Integer.MAX_VALUE, Integer::min);
System.out.println(smallestValue);
}
}
}