Java Utility Library

Java Objects - isNull() Method



The java.util.Objects.isNull() method returns true if the provided reference is null otherwise returns false.

Syntax

public static boolean isNull(Object obj)

Parameters

obj Specify a reference to be checked against null.

Return Value

Returns true if the provided reference is null otherwise false.

Exception

NA

Example:

In the example below, the java.util.Objects.isNull() method is used to check whether a specified object is null or not.

import java.util.*;

public class MyClass {
  public static void main(String[] args) {
    //creating Objects
    Object obj1 = 50;
    Object obj2 = null;
    
    //checking obj1 for null
    System.out.print("Is obj1 null: ");
    System.out.println(Objects.isNull(obj1));

    //checking obj2 for null
    System.out.print("Is obj2 null: ");
    System.out.println(Objects.isNull(obj2));
  }
}

The output of the above code will be:

Is obj1 null: false
Is obj2 null: true

❮ Java.util - Objects