Package java.util

Class Objects


  • public final class Objects
    extends Object
    Utility methods for objects.
    Since:
    1.7
    • Method Detail

      • 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.
      • 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().