Skip to content

Most visited

Recently visited

navigation
Added in API level 19

Objects

public final class Objects
extends Object

java.lang.Object
   ↳ java.util.Objects


Utility methods for objects.

Summary

Public methods

static <T> int compare(T a, T b, Comparator<? super T> c)

Returns 0 if a == b, or c.compare(a, b) otherwise.

static boolean deepEquals(Object a, Object b)

Returns true if both arguments are null, the result of equals(boolean[], boolean[]) if both arguments are primitive arrays, the result of deepEquals(Object[], Object[]) if both arguments are arrays of reference types, and the result of equals(Object) otherwise.

static boolean equals(Object a, Object b)

Null-safe equivalent of a.equals(b).

static int hash(Object... values)

Convenience wrapper for hashCode(), adding varargs.

static int hashCode(Object o)

Returns 0 for null or o.hashCode().

static <T> T requireNonNull(T o, String message)

Returns o if non-null, or throws NullPointerException with the given detail message.

static <T> T requireNonNull(T o)

Returns o if non-null, or throws NullPointerException.

static String toString(Object o, String nullString)

Returns nullString for null or o.toString().

static String toString(Object o)

Returns "null" for null or o.toString().

Inherited methods

From class java.lang.Object

Public methods

compare

Added in API level 19
int compare (T a, 
                T b, 
                Comparator<? super T> c)

Returns 0 if a == b, or c.compare(a, b) otherwise. That is, this makes c null-safe.

Parameters
a T
b T
c Comparator
Returns
int

deepEquals

Added in API level 19
boolean deepEquals (Object a, 
                Object b)

Returns true if both arguments are null, the result of equals(boolean[], boolean[]) if both arguments are primitive arrays, the result of deepEquals(Object[], Object[]) if both arguments are arrays of reference types, and the result of equals(Object) otherwise.

Parameters
a Object
b Object
Returns
boolean

equals

Added in API level 19
boolean equals (Object a, 
                Object b)

Null-safe equivalent of a.equals(b).

Parameters
a Object
b Object
Returns
boolean

hash

Added in API level 19
int hash (Object... values)

Convenience wrapper for hashCode(), adding varargs. This can be used to compute a hash code for an object's fields as follows: Objects.hash(a, b, c).

Parameters
values Object
Returns
int

hashCode

Added in API level 19
int hashCode (Object o)

Returns 0 for null or o.hashCode().

Parameters
o Object
Returns
int

requireNonNull

Added in API level 19
T requireNonNull (T o, 
                String message)

Returns o if non-null, or throws NullPointerException with the given detail message.

Parameters
o T
message String
Returns
T

requireNonNull

Added in API level 19
T requireNonNull (T o)

Returns o if non-null, or throws NullPointerException.

Parameters
o T
Returns
T

toString

Added in API level 19
String toString (Object o, 
                String nullString)

Returns nullString for null or o.toString().

Parameters
o Object
nullString String
Returns
String

toString

Added in API level 19
String toString (Object o)

Returns "null" for null or o.toString().

Parameters
o Object
Returns
String
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.