Java Hash Code Calculate hashCode(final int i)

Here you can find the source of hashCode(final int i)

Description

Computes the hash code for an integer.

License

Open Source License

Parameter

Parameter Description
i The integer for which a hash code should be computed.

Return

i.

Declaration

public static final int hashCode(final int i) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2000, 2006 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:/*from  w w w .j ava 2s . c om*/
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

public class Main {
    /**
     * Computes the hash code for an integer.
     * 
     * @param i
     *            The integer for which a hash code should be computed.
     * @return <code>i</code>.
     */
    public static final int hashCode(final int i) {
        return i;
    }

    /**
     * Computes the hash code for an object, but with defense against
     * <code>null</code>.
     * 
     * @param object
     *            The object for which a hash code is needed; may be
     *            <code>null</code>.
     * @return The hash code for <code>object</code>; or <code>0</code> if
     *         <code>object</code> is <code>null</code>.
     */
    public static final int hashCode(final Object object) {
        return object != null ? object.hashCode() : 0;
    }
}

Related

  1. hashCode(double v)
  2. hashCode(double val)
  3. hashCode(final byte[] data)
  4. hashCode(final char[] text, final int textOffset, final int textLen)
  5. hashCode(final int i)
  6. hashCode(final int seed, final int hashcode)
  7. hashCode(final int x, final int y)
  8. hashcode(final int[] array)
  9. hashCode(final long l)