Package java.util
Class Objects
java.lang.Object
java.util.Objects
public final class Objects extends Object
Utility methods for objects.
- Since:
- 1.7
-
Method Summary
Modifier and Type Method Description static <T> intcompare(T a, T b, Comparator<? super T> c)Returns 0 ifa == b, orc.compare(a, b)otherwise.static booleandeepEquals(Object a, Object b)Returns true if both arguments are null, the result ofArrays.equals(byte[], byte[])if both arguments are primitive arrays, the result ofArrays.deepEquals(java.lang.Object[], java.lang.Object[])if both arguments are arrays of reference types, and the result ofequals(java.lang.Object, java.lang.Object)otherwise.static booleanequals(Object a, Object b)Null-safe equivalent ofa.equals(b).static inthash(Object... values)Convenience wrapper forArrays.hashCode(boolean[]), adding varargs.static inthashCode(Object o)Returns 0 for null oro.hashCode().static <T> TrequireNonNull(T o)Returnsoif non-null, or throwsNullPointerException.static <T> TrequireNonNull(T o, String message)Returnsoif non-null, or throwsNullPointerExceptionwith the given detail message.static StringtoString(Object o)Returns "null" for null oro.toString().static StringtoString(Object o, String nullString)ReturnsnullStringfor null oro.toString().
-
Method Details
-
compare
Returns 0 ifa == b, orc.compare(a, b)otherwise. That is, this makescnull-safe. -
deepEquals
Returns true if both arguments are null, the result ofArrays.equals(byte[], byte[])if both arguments are primitive arrays, the result ofArrays.deepEquals(java.lang.Object[], java.lang.Object[])if both arguments are arrays of reference types, and the result ofequals(java.lang.Object, java.lang.Object)otherwise. -
equals
Null-safe equivalent ofa.equals(b). -
hash
Convenience wrapper forArrays.hashCode(boolean[]), adding varargs. This can be used to compute a hash code for an object's fields as follows:Objects.hash(a, b, c). -
hashCode
Returns 0 for null oro.hashCode(). -
requireNonNull
public static <T> T requireNonNull(T o)Returnsoif non-null, or throwsNullPointerException. -
requireNonNull
Returnsoif non-null, or throwsNullPointerExceptionwith the given detail message. -
toString
Returns "null" for null oro.toString(). -
toString
ReturnsnullStringfor null oro.toString().
-