Is there a simpler way to check multiple values against one value in an if-statement?

前端 未结 12 925
名媛妹妹
名媛妹妹 2020-11-27 07:55

Basically, what I want to do is check two integers against a given value, therefore, classically what you would do is something like this:

//just to get some         


        
12条回答
  •  半阙折子戏
    2020-11-27 08:22

    Here's a modification of @buc's answer that can take any number of any arguments:

    public  boolean oneOfEquals(T expected, T... os) {
        for (T o : os) {
            if (expected.equals(o)) return true;
        }
        return false;
    }
    

提交回复
热议问题