Java Utility Library

Java.util.Objects Class



Java Objects Class

Java.util package provides a Objects class which consists of static utility methods for operating on objects. These utilities include null-safe or null-tolerant methods for computing the hash code of an object, returning a string for an object, and comparing two objects.

Class declaration

The declaration of java.util.Objects class is:

public final class Objects
  extends Object

Here, E is the type of element maintained by the container.

java.util.Objects Methods

The java.util.Objects class has a number of methods which are listed below:

Member Methods

S.NMethods & Description
1. static boolean deepEquals(Object a, Object b)
Returns true if the arguments are deeply equal to each other and false otherwise.
2. static boolean equals(Object a, Object b)
Returns true if the arguments are equal to each other and false otherwise.
3. static int hash(Object... values)
Generates a hash code for a sequence of input values.
4. static int hashCode(Object obj)
Returns the hash code of a non-null argument and 0 for a null argument.
5. static boolean isNull(Object obj)
Returns true if the provided reference is null otherwise returns false.
6. static boolean nonNull(Object obj)
Returns true if the provided reference is non-null otherwise returns false.
7. static String toString(Object o)
Returns the result of calling toString for a non-null argument and "null" for a null argument.
8. static String toString(Object o, String nullDefault)
Returns the result of calling toString on the first argument if the first argument is not null and returns the second argument otherwise.

Methods inherited

This class inherits the methods of following class:

  • java.lang.Object