How to check if Number is Prime or not using Java 8 Streams API

In this post, we will see how to check if the number is prime or not with the help of Java 8 Streams API.

Easiest representation of Java 8 Streams power to test prime number... Check it out...!!! Click To Tweet

Let’s say: In this particular example, we are checking if ‘5’ is a prime number or not.

Note: you can specify any number you would like to check for in place of 5 in below example.

Example

 

Output:

Easiest representation of Java 8 Streams power to test prime number... Check it out...!!! Click To Tweet

 

That’s it, Java 8 Streams API is so powerful and notice how easily it simplified the way of checking the Prime number.

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

Other Useful References:

2 thoughts on “How to check if Number is Prime or not using Java 8 Streams API

Leave a Reply

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

Facebook Twitter Instagram YouTube