Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

communitycreator
java
object

What is Objects.isNull in Java?

abhilash

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

The method isNull is a static method of the Objects class in java that checks whether the input object reference supplied to it is null or not.

  • If the passed object is null, then the method returns true.
  • If the passed object is non-null, then the method returns false.

This method was introduced in Java 8. To use the nonNull method, import the following module:

java.util.Objects

Syntax

public static boolean isNull(Object obj)

Parameters:

This method takes one parameter, Object obj, an object reference to check against null.

Examples

In the code below, a non-null string object is passed to the isNull method, and returns false:

import java.util.Objects;
public class Main {
public static void main(String[] args) {
String s = "hello";
System.out.println(Objects.isNull(s));
}
}

In the code below, null is passed to the isNull method and returns true:

import java.util.Objects;
public class Main {
public static void main(String[] args) {
System.out.println(Objects.isNull(null));
}
}

RELATED TAGS

communitycreator
java
object

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring