[java] How to check if an integer is in a given range?

I think its already elegant way for comparing range. But, this approach cause you to write extra unit tests to satisfy all && cases.

So, you can use any of the below approach to avoid writing extra unit tests.

Using Java 8 Streams:

if(IntStream.rangeClosed(0,100).boxed().collect(Collectors.toList()).contains(i))

Using Math class:

if(Math.max(0, i) == Math.min(i, 100))

Personally I recommend the second approach because it won't end up creating an Array of the size equal to the range you want to check.