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
?
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…