Java Array Hash Code arrayHashCode(Object[] arr)

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

Description

Compute hash code of array.

License

Sun Public License Notice

Parameter

Parameter Description
arr array of objects, can contain <code>null</code>s

Return

the hash code

Declaration

public static int arrayHashCode(Object[] arr) 

Method Source Code

//package com.java2s;
/*/*from ww  w.j  av a2s  .c om*/
 *                 Sun Public License Notice
 *
 * The contents of this file are subject to the Sun Public License
 * Version 1.0 (the "License"). You may not use this file except in
 * compliance with the License. A copy of the License is available at
 * http://www.sun.com/
 *
 * The Original Code is NetBeans. The Initial Developer of the Original
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun
 * Microsystems, Inc. All Rights Reserved.
 */

public class Main {
    /** Compute hash code of array.
    * Asks all elements for their own code and composes the
    * values.
    * @param arr array of objects, can contain <code>null</code>s
    * @return the hash code
    * @see Object#hashCode
    */
    public static int arrayHashCode(Object[] arr) {
        int c = 0;
        int len = arr.length;
        for (int i = 0; i < len; i++) {
            Object o = arr[i];
            int v = o == null ? 1 : o.hashCode();
            c += (v ^ i);
        }
        return c;
    }
}

Related

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