I am trying to make a case where if the input equals any of these"@ ) ( & 1 2 3 4 5 6 7 8 9 0" then the input is ok and the program continues running. But if it does not then it sends the print statement. Obviously I could keep creating more and more "s.equals()" but this seems very inefficient. Is there another way that I am missing to accomplish the same goal but with less code?
// check here for invalid characters
for (String s : inputString.split("")) {
if (s.equals("@") || s.equals(")") || s.equals("(") || s.equals("&") || s.equals("1") || s.equals("2") || s.equals("3") || s.equals("4")) {
continue;
} else {
System.out.println("NO GOOD");
return;
}
}