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:

Author

  • Deepak Verma

    Deepak Verma is a Test Automation Consultant and Software development Engineer for more than 10 years. His mission is to help you become an In-demand full stack automation tester. He is also the founder of Techndeck, a blog and online coaching platform dedicated to helping you succeed with all the automation basics to advanced testing automation tricks.