dimanche 28 janvier 2018

dynamic if statement for string

How would I do something where I have 3 string variables, string1 string2 and string3 and depending on the user input some of those variables may be empty? I want to compare those variables to another 3 variables I already have set, unless the corresponding string (string1/string2/string3) input is empty

The idea is like this:

If none of them are empty then:

if (o.s1.equals(string1) && o.s2.equals(string2) && o.s3.equals(string3))

if s1 is the only one empty then we only compare the other 2:

if (o.s2.equals(string2) && o.s3.equals(string3))

So the program will not check if that variable is equal if the inputted string is empty

Is there a way to do this that isn't a bunch of nested if statements? I have 5 variables so there would be a lot of statements

Aucun commentaire:

Enregistrer un commentaire