How to check if any value in a one-dimensional array a is larger than x using anyMatch in Java

1 Answer

0 votes
import java.util.Arrays;

public class Main {
    public static void main(String[] args) {
        int[] arr = {1, 2, 3, 4, 5, 6, 7};
        int x = 4;

        boolean result = Arrays.stream(arr).anyMatch(value -> value > x);

        System.out.println("Is any value in the array larger than " + x + "? " + result);
    }
}


/*
run:

Is any value in the array larger than 4? true

*/


 



answered Jun 25 by avibootz
...