lundi 25 juillet 2016

better ways to compare to a set of Strings

Ok so I am working on this program that has an array of Strings. I would like to check and compare another string to this set of strings.

String[] myArray = {"hello", "how", "are", "you"};
String compare; 

if(myArray[0].equals(compare) || myArray[1].equals(compare) || myArray[2].equals(compare) || myArray[3].equals(compare)){
     //do stuff
}

This would work but is there another way that looks cleaner?

Aucun commentaire:

Enregistrer un commentaire