Now can I get String.equals(String... value) and maybe equalsOr(String... value). Always annoyed by comparing multiple values to a single string in a code block. If all or any are true do X.
You possibly want switch expressions, which are coming as a preview in Java 12. This means you'll need to enable a flag to make the compiler understand the language feature. This will cover your use-case:
var matches = switch( string) {
case "string1", "string2", "string3" -> true;
default -> false;
}
If you have an array, then this will work at the expense of creating an object.
var matches = Arrays.asList(strings).contains(string);
6
u/syntastical Sep 19 '18
Now can I get String.equals(String... value) and maybe equalsOr(String... value). Always annoyed by comparing multiple values to a single string in a code block. If all or any are true do X.