If statement, compare one variable to multiple

后端 未结 6 1313
挽巷
挽巷 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:15

    You could also use the Range class from apache commons :

    Range r = Range.between(1,3);
    if(r.contains(value)){
    
    }
    

提交回复
热议问题