Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
Is there any ready implementation of method
public static boolean equals(Object o1, Object o2) { return o1==null && o2==null || o1!=null && o2!=null && o1.equals(o2); }
somewhere in JRE/JDK?
o1 == null ? o2 == null : o1.equals(o2)
return (o1 == o2) || (o1 != null && o1.equals(o2));
If you are on JDK 7..
Objects.equals(a,b)
That's Objects with an s, which is in java.util, as in the utility library for objects, similar to Collections with an s and Arrays with an s.
Objects
s
java.util
Collections
Arrays
Add a comment
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
o1 == null ? o2 == null : o1.equals(o2)but not everybody likes using '?'. On the other hand, with JDK 7 Objects is the better way as @niels-bech-nielsen pointed in his answer.return (o1 == o2) || (o1 != null && o1.equals(o2));:) which is what is implemented in JDK as well.