Hello All, Can anyone suggest me, where I am wrong in this code? I have to compare two Boolean wrappers with each other. As a result I don’t know they are equal or not.
This is what I came up with:
public static boolean areEqual(final Boolean a, final Boolean b) {
if (a == b) {
return true;
}
if (a != null && b != null) {
return a.booleanValue() == b.booleanValue();
}
return false;
}
By using the java compiler on interviewbit, Is there a better and/or shorter way to correctly compare two Boolean wrappers for equality?
First I wanted to use Object.equals() or Boolean.compareTo() but both ways could end up in a NullPointerException , right? Any Suggestions
Thanks in Advance!