Convert a string to hash in Java

hashCode() method of String class can be used to convert a string into hash code.

hashCode() method will return either negative or positive integer hash values. The returned hash value cannot be re-converted back to string once hashed.


Example 1

class StringTest{

public static void main(String args[]){

String str="Everyone is equal";

int hashedvalue=str.hashCode();

System.out.println("Hashed value is "+hashedvalue);

}

}

Output 1

Hashed value is 1346529203


Example 2

class StringTest{

public static void main(String args[]){

String str1="You are awesome";

int hashedvalue=str1.hashCode();

System.out.println("Hashed value is "+hashedvalue);

}

}

Output 2

Hashed value is -1357061130