Get String hash code in Java
Description
The following code shows how to get String hash code.
Example
/* w w w . j av a2 s .c om*/
public class Main {
public static void main(String[] args) {
String s1 = "abc";
String s2 = "abc";
String s3 = "def";
System.out.println("s1 hash code = " + s1.hashCode());
System.out.println("s2 hash code = " + s2.hashCode());
System.out.println("s3 hash code = " + s3.hashCode());
}
}
The code above generates the following result.
Home »
Java Tutorial »
Java Data Type »
Java Tutorial »
Java Data Type »