Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java objects compare with null cases?

Tags:

java

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?

like image 472
Dims Avatar asked Dec 28 '25 10:12

Dims


1 Answers

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.

like image 76
Niels Bech Nielsen Avatar answered Dec 31 '25 00:12

Niels Bech Nielsen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!