Pascal has a feature of set types. It allows nice constructs like this:
if i in [5..10] then
...
Are there any similar things in Java?
I came up only with this ugly construction that doesn’t accept intervals:
if ((new HashSet<Integer>(Arrays.asList(new Integer[]{5,6,7,8,9,10}))).contains(i))
...
Yes you’re right. You need an implementation of a
Setin Java and have to populate it yourself with a loop if you want a non-sequential list of numbers.Also, Java does not support the contruct of a Range. Other JVM laguages like Groovy and Scala however do.
This post may add some more colour