jeudi 2 novembre 2017

if conditions avoid repetitions

I have three if conditions something like below

if ((class1.getMethod1().subString(0,1) == "1") && !class1.getMethod1().subString(0,1).equalsIgnoreCase(str1.subString(0,1))
if ((class1.getMethod1().subString(0,1) == "2") && !class1.getMethod1().subString(0,1).equalsIgnoreCase(str1.subString(0,1))
if ((class1.getMethod1().subString(0,1) == "3") && !class1.getMethod1().subString(0,1).equalsIgnoreCase(str1.subString(0,1))

All the if conditions are gonna do same stuff. Is there anyway I can avoid repeating these many if conditions and make it in a single line ?

Aucun commentaire:

Enregistrer un commentaire