What does the method hashCode(int[] a) do in java?
The hashCode(int[]) method of the java.util.Arrays class returns a hash code based on the contents of the specified array. For any two non-null int arrays a and b such that Arrays.equals(a, b), it is also the case that Arrays.hashCode(a) == Arrays.hashCode(b).
Example
import java.util.Arrays;
public class ArrayDemo {
public static void main(String[] args) {
int[] ival = new int[] { 3, 5 };
int retval = ival.hashCode();
System.out.println("The hash code of value1 is: " + retval);
ival = new int[] { 19, 75 };
retval = ival.hashCode();
System.out.println("The hash code of value2 is: " + retval);
}
}
Output
The hash code of value1 is: 4072869
The hash code of value2 is: 1671711
Published on 16-Jan-2018 10:37:18
- Related Questions & Answers
- What does the method hashCode(obj[] a) do in java?
- What does the method fill(int[], int val) do in java?
- What does the method sort(int[] a, int fromIndex, int toIndex) do in java?
- What does the method sort(int[] a) do in java?
- What does the method int capacity() do in java?
- What does the method get(int) do in java?
- What does the method remove(int) do in java?
- What does the method toString(int[] a) do?
- What does the method removeRange(int fromIndex, int toIndex) do in java?
- What does the method equals(int[] a1, int[] a2) do in java?
- What does the method copyOf(int[] original, int newLength) do in java?
- What does the method fill(int[], int fromIndex, int toIndex, int val) do in java?
- What does the method copyOfRange(int[] original, int from, int to) do in java?
- What does the method sort(obj[] a, int fromIndex, int toIndex) do in java?
- What does the method ensureCapacity(int, minCapacity) do in java?