#equals()
1 messages · Page 1 of 1 (latest)
<@&987246399047479336> please have a look, thanks.
You can use </chatgpt:1108714622413963314> to ask ChatGPT about your question while you wait for a human to respond.
That will lead to a nullpointerexception.
You're asking something that's potentially null: am I null?
You can also just use Objects.equals()
I see now. Appreciate it, thanks!
FYI
if (a.equals(null) && b.equals(null)) { // NullPointerException if a or b are null
return true; // this is never executed becuse anything.equals(null) is false.
}
if (a.equals(null) || b.equals(null)) { // NullPointerException if a or b are null
return false; // this is never executed becuse anything.equals(null) is false.
}
And Simon_Verhoeven says, use Objects.equals(a, b) instead.
what happens if you just return firstString.equals(SecondString); ???
It would also throw a NPE if firstString was null.
All that code you wrote is like Simon said, just Objects.equals(firstString, secondString)