How to check if all the elements of array is even using stream in Java

1 Answer

0 votes
import java.util.Arrays; 

public class MyClass {
    public static void main(String args[]) {
        int arr[] = {2, 4, 6, 8, 10, 12};
            
        System.out.println(Arrays.stream(arr) 
                                 .allMatch(val->val % 2 == 0)); 
    }
}




/*
run:

true

*/

 



answered Oct 2, 2019 by avibootz
...