I am seeing if there is a better/nicer way of writing a long if statement using multiple ||
operators.
After looking online I see a lot of examples using conditional binomial operator. Is there a way this can be used when checking if a string equals a word?
The examples online follow this structure:
int price = condition?80:100;
Here is the function:
public boolean validateLetters(String word) {
if (word.equals("apple") || word.equals("excel") || word.equals("intern")
|| word.equals("orange") || word.equals("car")) {
return true;
}
return false;
}
The function checks to see the parameter word matches one of the following.
Is there a nicer or more efficient way I could write it?