0

I have the following function, where I have to check for a particular value and print some output. Since I have same operation for multiple int values , I tried using arrayList.

public static final List<Integer> randomNumbers = Collections.unmodifiableList(
        new ArrayList<Integer>() {{
            add(7);
            add(9);
            etc...
        }});


public void checkNumbers(int state) {
    //This is existing
    if (state == 7 || state == 9) {
        //do something
    }

    // I can use this
    if (state == randomNumbers.get(0) || state == randomNumbers.get(1)) {
        //do something
    }
}

Is there any other simpler way to compare the entire arraylist ?

cantona_7
  • 1,127
  • 4
  • 21
  • 40

0 Answers0