SyntaxFix
Write A Post
Hire A Developer
Questions
Keep the acceptable values in a HashSet and check if your string exists using the contains method:
HashSet
Set<String> accept = new HashSet<String>(Arrays.asList(new String[] {"john", "mary", "peter"})); if (accept.contains(some_string)) { //... }