We all know about intervals in mathematics (e.g. -4 <x <3).
How can I represent these mathematical intervals in Java, for example numbers from -4 to 3 (-4, -3, ..., 2, 3, etc.)?
Check apache commons-lang IntRange. So, if you want to check if a number is in a given interval (range), follow these steps:
IntRange
IntRange range = new IntRange(-4, 3); if (range.contains(x)) { .... }
You just need to separate -4 < x < 3before -4 < xand x < 3for example:
-4 < x < 3
-4 < x
x < 3
if (-4 < x && x < 3) { . . . }
Google Guava also has a Range class ( http://docs.guava-libraries.googlecode.com/git-history/v10.0/javadoc/com/google/common/collect/Range.html ) that might work for you.