Print Only Even Numbers in Array Using Streams in Java

In this article, I will explain how to print only even numbers from integer array using streams in java.

1)Lets take numbers array and initialize with some values

2)Then Arrays.stream(numberArray) with give you stream object. There you have lots of methods. Since we need to filter only even numbers we can apply filter method with predicate as x%2==0

3)Then on top of that result apply for each loop and print numbers.

 int[] numbers = new int[]{2,1,3,5,6,7,8,9};
Arrays.stream(numbers).filter(x->x%2==0)
		.forEach(x-> System.out.println(x))

Full tutorial here –

https://youtu.be/GMbONOvKHPM

Loading


Comments

Leave a Reply

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