You can easily create an array booleanand just shift the index:
int minValueInclusive = -15;
int maxValueExclusive = 31;
boolean[] presence = new boolean[maxValueExclusive - minValueInclusive + 1];
for (int value : array) {
presence[value - minValueInclusive] = true;
}
:
if (presence[index - minValueInclusive]) {
...
}
, 64 , long .
int minValueInclusive = -15;
long presence = 0;
for (int value : array) {
presence |= 1L << (value - minValueInclusive);
}
:
if ((presence & (1L << (index - minValueInclusive))) != 0) {
...
}