Java 8 Stream Methods Examples – count(), max(), min(), findAny() and findFirst()

Java 8 Stream came up with methods: count(), max(), min(), findAny(), findFirst(). In this post, we will learn how to use these methods.

Let’s discuss first what these methods are:

count()  This method returns the count of elements of a stream.

max() – This method returns the maximum element of a stream.

min() –  This method returns the minimum element of a stream.

findAny() – This method returns an java.util.Optional describing some element of the stream, or an empty java.util.Optional if the stream is empty.

findFirst() – This method  returns an java.util.Optionaldescribing the first element of this stream, or an empty java.util.Optional if the stream is empty.

Find Count, Max, Min, findAny & findFirst using Java 8 Streams methods...!!! Click To Tweet

Let’s Begin,

Example:

 

Output:

 

Find Count, Max, Min, findAny & findFirst using Java 8 Streams methods...!!! Click To Tweet

Do you like this Post? – then check my other helpful posts:

Other Useful References:

 

Related Posts:

[wcp-carousel id=”5342″]

Leave a Reply

Your email address will not be published.Required fields are marked *

Facebook Twitter Instagram YouTube