Here you can find the source of hashCode(String sIn)
In contrast to .hashCode(), this function returns a positive Integer.
Parameter | Description |
---|---|
sIn | The String to get a hashcode for. |
public static String hashCode(String sIn)
//package com.java2s; //License from project: Open Source License public class Main { /**//from w w w .j ava 2s.com * Return a hashcode as a positive Integer for a String.<p> * * In contrast to .hashCode(), this function returns a positive * Integer. This is helpful to use Strings as a unique key in * places (e.g. JavaScript) where you would be bothered by * special characters in the String. * * @param sIn The String to get a hashcode for. * @return The hashcode as a positive Integer in a String. */ public static String hashCode(String sIn) { if (sIn == null) { return null; } return "" + Math.abs(sIn.hashCode()); } }