How to check whether any element in array is divisible by N or not using stream in Java

1 Answer

0 votes
import java.util.Arrays; 
import java.util.function.IntPredicate; 

public class MyClass {
    public static void main(String args[]) {
        int arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 6, 10, 11, 12};
            
        IntPredicate ipredicate = val->val % 9 == 0; 
        
        System.out.println(Arrays.stream(arr) 
                                 .anyMatch(ipredicate)); 
    }
}




/*
run:

false

*/

 



answered Oct 2, 2019 by avibootz

Related questions

...