Reduce length of condition Is there a way to reduce this lengthy if condition:

if(
    statusCode.equals( NO_ERRORS_NO_WARNINGS ) ||
    statusCode.equals( HAS_ERRORS_NO_WARNINGS )  ||
    statusCode.equals( HAS_ERRORS_HAS_WARNINGS ) ||
    statusCode.equals( NO_ERRORS_HAS_WARNINGS )
){
    //do something
}


The purpose of it is to see if there is a status code set within a log file. So the String statusCode could be a null value, one of the 4 status codes above or an unpredicatable String.
First of all, if statusCode can be null, the code above could possibly throw a null pointer exception.

To directly answer your question though, you could use a Set, such as a HashSet.

HashSet&lt;String&gt; errorOrWarning = new HashSet&lt;String&gt;();
errorOrWarning.add(HAS_ERRORS_HAS_WARNINGS);
errorOrWarning.add(HAS_ERRORS_NO_WARNINGS);
errorOrWarning.add(HAS_ERRORS_HAS_WARNINGS);
errorOrWarning.add(NO_ERRORS_HAS_WARNINGS);


Which you can then use in a single call.

if (errorOrWarning.contains(statusCode) {
    // do something
}


This has the advantage that statusCode can be null and it would produce no exception.