From e4dd5ee359990775fad6dbafdc5320f09cb54b03 Mon Sep 17 00:00:00 2001 From: Praveen Kulkarni Date: Sat, 23 Sep 2023 11:39:02 -0400 Subject: [PATCH] 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 --- .../lambdasinaction/chap5/PuttingIntoPractice.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/lambdasinaction/chap5/PuttingIntoPractice.java b/src/main/java/lambdasinaction/chap5/PuttingIntoPractice.java index d0b13ae5..6df02bde 100644 --- a/src/main/java/lambdasinaction/chap5/PuttingIntoPractice.java +++ b/src/main/java/lambdasinaction/chap5/PuttingIntoPractice.java @@ -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); } -} \ No newline at end of file +}