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,

String hashCode() method in Java

String getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin) method in Java
String indexOf(int ch) method in Java
Studyopedia Editorial Staff
[email protected]

We work to create programming tutorials for all.

No Comments

Post A Comment