Check more ints in a range

Viewed 54

Is there any simpler way to check more than one number in a range? I have to check if three parameters of a method are in range 10 (inclusive) - 1000 (inclusive). Can it be written nicer than this?

(x < 10) || (x > 1000) || (y < 10) || (y > 1000) || (z < 10) || (z > 1000)
1 Answers

You can use an IntStream.

Like,

if (IntStream.of(x, y, z).anyMatch(a -> a < 10 || a > 1000))
Related