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
For more context what I'm trying to do with this is something like a search function where there are 3 conditions, if all 3 of those fields are filled then it will search for something that meets all 3 conditions, but if one of those are empty then it will only look for entries that meet 2 of the conditions, and if 2 are empty it will search for entries that only satisfy that one condition.
==or!=. Use theequals(...)or theequalsIgnoreCase(...)method instead. Understand that==checks if the two object references are the same which is not what you're interested in. The methods on the other hand check if the two Strings have the same characters in the same order, and that's what matters here.if (o.s1.isEmpty()) {or its converse where needed?null?""?