String.equals() with multiple conditions (and one action on result)
android, java
Solution
Possibilities:
Use `String.equals()`:
if (some_string.equals("john") ||
some_string.equals("mary") ||
some_string.equals("peter"))
{
}
Use a regular expression:
if (some_string.matches("john|mary|peter"))
{
}
Store a list of strings to be matched against in a Collection and search the collection:
Set<String> names = new HashSet<String>();
names.add("john");
names.add("mary");
names.add("peter");
if (names.contains(some_string))
{
}
Problem
Is it possible to do something like this in Java for Android (this is a pseudo code) ``` IF (some_string.equals("john" OR "mary" OR "peter" OR "etc."){ THEN do something } ``` ? At the moment this is done via multiple `String.equals()` condition with `||` among them.