I want to compare two strings for equality when either or both can be null.
So, I can't simply call .equals() as it can contain null values.
The code I have tried so far :
boolean compare(String str1, String str2) {
return ((str1 == str2) || (str1 != null && str1.equals(str2)));
}
What will be the best way to check for all possible values including null ?
compare, it has a different meaning for strings. You should call itequals.