Saturday, 7 October 2023

1. Given a list of integers, find out all the even numbers that exist in the list using Stream functions? By Java 8

 


Description:
Given a list of integers, find out all the even numbers that exist in the list using Stream functions?

Code:
?
1
2
3
4
5
import java.util.*; import java.util.stream.*; public class EvenNumber { public static void main(String args[]) { List<Integer> list = Arrays.asList(10, 15, 8, 49, 25, 98, 32); list.stream().filter(n -> n % 2 == 0).forEach(System.out::println); }

Output: 10, 8, 98, 32