Java 8 stream min max comparator examples

Today, i show you about Java 8 stream min max comparator examples which finds min and max date, number, Char, String or object from stream of comparable elements using Comparator.comparing() method. Java 8 introduced several enhancements to the Comparator interface, including a handful of static functions that are of great utility.

Min or Max Number

Now we have a comparator for integer number like this

Demo program

Output

Min or Max String

Now we have a comparator for string like this

Our demo program

Output

Min or Max Date

Now we have a comparator for string like this

Demo program

Output

Min or Max Object

We’re considering the POJO like this

And We’re finding the max and min age of people, so our comparator should be such as

Demo program

Output
Java 8 stream min max comparator examples

That’s all about Java 8 stream min max comparator examples.

References
Comparator (Java Platform SE 8)

Download the complete source code, click link below

StreamMinMaxExamples.zip (5 downloads)

Leave a Comment

*

Please share it if you found this useful
Hide Buttons