Java Hash Code Calculate hashCode(final Object obj)

Here you can find the source of hashCode(final Object obj)

Description

Calculate hashcode of objects.

License

LGPL

Parameter

Parameter Description
obj Object , if the object is array then the calculated hashcode is for every object in the array

Return

calculated hashcode

Declaration

public static int hashCode(final Object obj) 

Method Source Code

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

public class Main {
    /**/*from   w w  w  .  jav a  2s.co  m*/
     * Calculate hashcode of objects. This method calculate hashcode for every
     * instance in arrays.
     * 
     * @param obj
     *            {@link Object}, if the object is array then the calculated
     *            hashcode is for every object in the array
     * @return calculated hashcode
     */
    public static int hashCode(final Object obj) {
        if (obj == null) {
            return 0;
        }
        if (obj.getClass().isArray()) {
            Object[] array = (Object[]) obj;
            int result = 17;
            for (int i = 0; i < array.length; i++) {
                result = result * 37 + hashCode(array[i]);
            }
            return result;
        }
        return obj.hashCode();
    }
}

Related

  1. hashCode(final int x, final int y)
  2. hashcode(final int[] array)
  3. hashCode(final long l)
  4. hashCode(final long l)
  5. hashCode(final long v)
  6. hashCode(final Object obj)
  7. hashCode(final Object object)
  8. hashCode(final Object... array)
  9. hashCode(float value)