Java Hash Code Calculate hashCode(Object objects[])

Here you can find the source of hashCode(Object objects[])

Description

Creates a combined hash for an array of objects.

License

Open Source License

Parameter

Parameter Description
objects The objects to hash

Return

The combined hashCode of the objects.

Declaration

public static int hashCode(Object objects[]) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2009, 2010 Cloudsmith Inc. 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 a  v  a  2  s  . c om
 *     Cloudsmith Inc. - initial API and implementation
 *******************************************************************************/

public class Main {
    /**
     * Creates a combined hash for an array of objects.
     * @param objects The objects to hash
     * @return The combined hashCode of the objects.
     */
    public static int hashCode(Object objects[]) {
        if (objects == null)
            return 0;

        int result = 1;
        int idx = objects.length;
        while (--idx >= 0) {
            Object object = objects[idx];
            result = 17 * result + (object == null ? 0 : object.hashCode());
        }
        return result;
    }
}

Related

  1. hashCode(Object obj)
  2. hashCode(Object object)
  3. hashCode(Object object)
  4. hashCode(Object object)
  5. hashCode(Object object)
  6. hashCode(Object value)
  7. hashCode(Object value)
  8. hashCode(Object value)
  9. hashCode(Object value)