Java Array Hash Code arrayHashCode(Object[] arr)

Here you can find the source of arrayHashCode(Object[] arr)

Description

array Hash Code

License

Apache License

Declaration

public static int arrayHashCode(Object[] arr) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static int arrayHashCode(Object[] arr) {
        int hash = 0;
        if (arr != null) {
            // Avoid that 2 arrays of length 0 but different classes return same
            // hash
            hash ^= arr.getClass().hashCode();
            for (int i = 0; i < arr.length; ++i) {
                hash ^= arr[i] == null ? 0 : arr[i].hashCode();
            }//from  w  ww  .  j  av  a 2s. c  om
        }
        return hash;
    }

    public static int arrayHashCode(byte[] arr) {
        int hash = 0;
        if (arr != null) {
            // Avoid that 2 arrays of length 0 but different classes return same
            // hash
            hash ^= arr.getClass().hashCode();
            for (int i = 0; i < arr.length; ++i) {
                hash ^= arr[i];
            }
        }
        return hash;
    }
}

Related

  1. arrayHashCode(Object array[])
  2. arrayHashCode(Object[] arr)
  3. arrayHashCode(Object[] objects)
  4. byteArrayHashCode(final byte[] array)
  5. calculateHash(byte[] data)
  6. deepHash(Object[] t)