Since this question has been reopened anyway, I might just as well propose an enum
solution.
enum ValidValues {
VAL1, VAL2, VAL3;
public static boolean isValid(String input) {
return Stream.of(ValidValues.values())
.map(ValidValues::name)
.anyMatch(s -> s.equalsIgnoreCase(input));
}
}
Or you can just use the stream statement with
Stream.of("val1", "val2", "val3")
.anyMatch(s -> s.equalsIgnoreCase(str))
if you only use it in one place.