14 May String hashCode() method in Java
The hashCode() method in Java returns a hash code for this string.
Syntax
Let us see the syntax,
int hashCode()
Parameters
The method has no parameters.
Example
The following is an example of hashCode(),
public class StudyopediaDemo {
public static void main(String args[]) {
String message1 = new String("Australia is a country!");
System.out.println("Hashcode= " + message1.hashCode() );
String message2 = new String("India is a country!");
System.out.println("Hashcode= " + message2.hashCode() );
}
}
Output
The following is the output,

No Comments