WEB DEVELOPER SITE
PHP7
 

Java String hashCode() Method



This method returns a hash code for this string. The hash code for a String object is computed as โˆ’

s[0]*31^(n - 1) + s[1]*31^(n - 2) + ... + s[n - 1]

Syntax

Here is the syntax of this method โˆ’

public int hashCode()

Parameters

Here is the detail of parameters โˆ’

  • This is a default method and this will not accept any parameters.

Return Value

  • This method returns a hash code value for this object.

Example

import java.io.*;
public class Test {

   public static void main(String args[]) {
      String Str = new String("Welcome to Welookups.com");
      System.out.println("Hashcode for Str :" + Str.hashCode() );
   }
}

Run example ยป