If statement, compare one variable to multiple

后端 未结 6 1315
挽巷
挽巷 2021-01-22 10:53

Example:

int value = someValue;
if (value == (valueOne OR valueTwo OR valueThree)){
//do code
}

I would like to avoid re-typing value

6条回答
  •  执笔经年
    2021-01-22 11:25

    This would do it in one check:

    int value = someValue;
    if(Arrays.asList(valueOne, valueTwo, valueThree).contains(someValue)){
        // do the things
    }
    

提交回复
热议问题