Objects.isNull vs object == null | Which one should I use?

If you look at the source code of IsNull method,

 /* Returns true if the provided reference is null otherwise returns false.*/ public static boolean isNull(Object obj) {     return obj == null; }

It is the same. There is no difference.

To check for null values, you can use:

  • Objects.isNull(myObject)
  • null == myObject // avoids assigning by typo
  • myObject == null // risk of typo

The fact that Objects.isNull is meant for Predicates does not prevent you from using it as above.

Objects.isNull is intended for use within Java 8 lambda filtering.

It’s much easier and clearer to write


than to write

.stream().filter(x -> x == null).

Within an, if however either will work, the use of == null is probably easier to read but in the end, it will boil down to a style preference.