[Solved] Cleaner way to write code snippet


if you’re only comparing a few values then you might as well proceed with the current approach as there is nothing in place to make it shorter. However, if you’re repeating your self many times, then you can create a helper function to do the work for you.

i.e

static boolean anyMatch(int comparisonValue, int... elements){
        return Arrays.stream(elements)
                     .anyMatch(e -> e == comparisonValue);
}

then call it like so:

if(anyMatch(10, a, b)){ ... }

solved Cleaner way to write code snippet