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 Details

    • compare

      public static <T> 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.
    • deepEquals

      public static boolean deepEquals​(Object a, Object b)
      Returns true if both arguments are null, the result of Arrays.equals(byte[], byte[]) if both arguments are primitive arrays, the result of Arrays.deepEquals(java.lang.Object[], java.lang.Object[]) if both arguments are arrays of reference types, and the result of equals(java.lang.Object, java.lang.Object) otherwise.
    • equals

      public static boolean equals​(Object a, Object b)
      Null-safe equivalent of a.equals(b).
    • hash

      public static int hash​(Object... values)
      Convenience wrapper for Arrays.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

      public static int hashCode​(Object o)
      Returns 0 for null or o.hashCode().
    • requireNonNull

      public static <T> T requireNonNull​(T o)
      Returns o if non-null, or throws NullPointerException.
    • requireNonNull

      public static <T> T requireNonNull​(T o, String message)
      Returns o if non-null, or throws NullPointerException with the given detail message.
    • toString

      public static String toString​(Object o)
      Returns "null" for null or o.toString().
    • toString

      public static String toString​(Object o, String nullString)
      Returns nullString for null or o.toString().