What does the method hashCode(int[] a) do in java?

Java 8Object Oriented ProgrammingProgramming

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
raja
Published on 16-Jan-2018 10:37:18
Advertisements