I have two strings ...
String s1 = /* any string, could be null */;
String s2 = /* any string, could be null */;
I need to know if they are equal.
I can't do s1.equals(s2)
because NullPointer if s1 == null
.
Is this the best way to check if they are equal?
public boolean stringsAreEqual(String s1, String s2) {
boolean bEqual = false;
if ((s1 == null) && (s2 == null)) {
bEqual = true;
} else if ((s1 != null) && s1.equals(s2)) {
bEqual = true;
} else if ((s2 != null) && s2.equals(s1)) {
bEqual = true;
}
return bEqual;
}