How to check if an object is null in Java?

To check if an object is null in Java, do this: object == null.

Here's how you do it:

Object object = null;
boolean isNull = object == null;

System.out.println(isNull); // true

Or with a utility class

Another way is to use the Objects class:

Object object = null;
boolean isNull = java.util.Objects.isNull(object);

System.out.println(isNull); // true