Here you can find the source of hashCode(Object obj)
public static int hashCode(Object obj)
//package com.java2s; /*// w ww.ja va2 s . c o m * Copyright (c) 2015, Alachisoft. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public class Main { public static int hashCode(Object obj) { if (obj instanceof String) { char[] array = ((String) obj).toCharArray(); int[] intArray = new int[(int) Math.ceil((double) (array.length) / 2)]; for (int i = 0, j = 0; i < intArray.length; i++) { char[] toInt = new char[2]; if (j < array.length) { toInt[0] = array[j++]; } if (j < array.length) { toInt[1] = array[j++]; } intArray[i] = charToInt(toInt); } int num = 0x15051505; int num2 = num; for (int i = array.length, j = 0; i > 0; i -= 4, j += 2) { num = (((num << 5) + num) + (num >> 0x1b)) ^ intArray[j]; if (i <= 2) { break; } num2 = (((num2 << 5) + num2) + (num2 >> 0x1b)) ^ intArray[j + 1]; } return (num + (num2 * 0x5d588b65)); } else return obj.hashCode(); } private static int charToInt(char[] array) { return (array[0] | (array[1] << 16)); } }