I want to compare two strings for equality when either or both can be null.
null
So, I can\'t simply call .equals() as it can contain null<
.equals()
null<
You can use java.util.Objects as following.
java.util.Objects
public static boolean compare(String str1, String str2) { return Objects.equals(str1, str2); }