I want to compare two strings for equality in Java, when either or both could be null, so I cannot simply call .equals(). What is the best way?
boolean compare(String str1, String str2) {
...
}
return ((str1 == str2) || (str1 != null && str1.equals(str2)));