Java Utils - Objects.isNull() Examples

Code Snippets Java Utils Java 


Class:

java.util.Objects

java.lang.Objectjava.lang.Objectjava.util.Objectsjava.util.ObjectsLogicBig

Method:

public static boolean isNull(Object obj)

Returns true if the provided reference is null otherwise returns false. Useful if used as a java.util.function.Predicate.


Examples


package com.logicbig.example.objects;

import java.util.Objects;

public class IsNullExample {

public static void main(String... args) {
String str = "testString";
//equivalent to obj == null;
boolean b = Objects.isNull(str);
System.out.println(b);
}
}

Output

false




package com.logicbig.example.objects;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;

public class IsNullExample2 {

public static void main(String... args) {
List<String> list = Arrays.asList("a", "b", null, null);
boolean b = list.stream().anyMatch(Objects::isNull);
System.out.println(b);
}
}

Output

true




See Also