- Java.util - Home
- Java.util - ArrayDeque
- Java.util - ArrayList
- Java.util - Arrays
- Java.util - BitSet
- Java.util - Calendar
- Java.util - Collections
- Java.util - Currency
- Java.util - Date
- Java.util - Dictionary
- Java.util - EnumMap
- Java.util - EnumSet
- Java.util - Formatter
- Java.util - GregorianCalendar
- Java.util - HashMap
- Java.util - HashSet
- Java.util - Hashtable
- Java.util - IdentityHashMap
- Java.util - LinkedHashMap
- Java.util - LinkedHashSet
- Java.util - LinkedList
- Java.util - ListResourceBundle
- Java.util - Locale
- Java.util - Observable
- Java.util - PriorityQueue
- Java.util - Properties
- Java.util - PropertyPermission
- Java.util - PropertyResourceBundle
- Java.util - Random
- Java.util - ResourceBundle
- Java.util - ResourceBundle.Control
- Java.util - Scanner
- Java.util - ServiceLoader
- Java.util - SimpleTimeZone
- Java.util - Stack
- Java.util - StringTokenizer
- Java.util - Timer
- Java.util - TimerTask
- Java.util - TimeZone
- Java.util - TreeMap
- Java.util - TreeSet
- Java.util - UUID
- Java.util - Vector
- Java.util - WeakHashMap
- Java.util - Interfaces
- Java.util - Exceptions
- Java.util - Enumerations
- Java.util Useful Resources
- Java.util - Useful Resources
- Java.util - Discussion
Java Arrays deepHashCode() Method
Description
The Java Arrays deepHashCode(Object[]) method returns a hash code based on the "deep contents" of the specified array.For any two arrays a and b such that Arrays.deepEquals(a, b), it is also the case that Arrays.deepHashCode(a) == Arrays.deepHashCode(b).
Declaration
Following is the declaration for java.util.Arrays.deepHashCode() method
public static int deepHashCode(Object[] a)
Parameters
a − This is the array whose deep-content-based hash code to compute.
Return Value
This method returns a deep-content-based hash code for a.
Exception
- NA
Getting Deep Hashcode from an Array of Strings Example
The following example shows the usage of Java Arrays deepHashCode(Object[]) method. In this example, we've created one array of Strings and computed their hashcode using deepHashCode() method and printed
package com.tutorialspoint;
import java.util.Arrays;
public class ArrayDemo {
public static void main(String[] args) {
//initializing an string array
String[] stringArr = { "tuts","point" };
// deepHashCode for String array
int retval = Arrays.deepHashCode(stringArr);
// printing value
System.out.println("The Hash Code of stringArr is:" + retval);
}
}
Output
Let us compile and run the above program, this will produce the following result −
The Hash Code of stringArr is:217575569
Getting Deep Hashcode from an Array of Integers Example
The following example shows the usage of Java Arrays deepHashCode(Object[]) method. In this example, we've created one array of Integers and computed their hashcode using deepHashCode() method and printed
package com.tutorialspoint;
import java.util.Arrays;
public class ArrayDemo {
public static void main(String[] args) {
//initializing an integer array
Integer[] intArr = { 1, 2 };
// deepHashCode for Integer array
int retval = Arrays.deepHashCode(intArr);
// printing value
System.out.println("The Hash Code of intArr is:" + retval);
}
}
Output
Let us compile and run the above program, this will produce the following result −
The Hash Code of intArr is:994
Getting Deep Hashcode from an Array of Objects Example
The following example shows the usage of Java Arrays deepHashCode(Object[]) method. In this example, we've created one array of Student objects and computed their hashcode using deepHashCode() method and printed.
package com.tutorialspoint;
import java.util.Arrays;
public class ArrayDemo {
public static void main(String[] args) {
//initializing an Student array
Student[] studentArr = { new Student(1, "Julie"), new Student(2, "Robert"), new Student(3, "Adam") };
// deepHashCode for Student array
int retval = Arrays.deepHashCode(studentArr);
// printing value
System.out.println("The Hash Code of studentArr is:" + retval);
}
}
class Student {
int rollNo;
String name;
Student(int rollNo, String name){
this.rollNo = rollNo;
this.name = name;
}
@Override
public String toString() {
return "[ " + this.rollNo + ", " + this.name + " ]";
}
}
Output
Let us compile and run the above program, this will produce the following result −
The Hash Code of studentArr is:-1497234753