mercredi 14 janvier 2015

java: most concise way to compare one variable against several others

Often I find myself writing if statements like this...



if (name.equals("fred") || name.equals("bob") || name.equals("jack")){

}


or with primitives...



if (numb==4 || numb==45 || numb=91){

}


Is there a more concise way to do this?


Aucun commentaire:

Enregistrer un commentaire