I want to find the most efficient/fastest way of checking if a string belongs in an array in both Java and JavaScript.
For example, I want to find if the string "="
belongs in the array {"+", "-", "=", "*", "/", "!"}
A way to do it in Java is(omitting the main method)
String[] symbols = {"+", "-", "=", "*", "/", "!"};
String equalTo = "=";
for(String i: symbols) {
if(equalTo.equals(i)) {
System.out.print(equalTo + " belongs to symbols.");
}
}
I would like to know if there is a single method which does this work for me in either Java and JavaScript.
The reason I am asking this in both languages is that I want to see if it is easier in Java or JavaScript.