Open In App

Scala String hashCode() method with example

Last Updated : 03 Oct, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

The hashCode() method is utilized to find the hash code of the stated string.

Method Definition: int hashCode()
Return Type: It returns an integer hash code of the string given.

Example #1:




// Scala program of int hashCode()
// method
  
// Creating object
object GfG
  
    // Main method
    def main(args:Array[String])
    {
      
        // Applying hashCode method
        val result = "Nidhi".hashCode()
          
        // Displays output
        println(result)
      
    }


Output:

75262122

Example #2:




// Scala program of int hashCode()
// method
  
// Creating object
object GfG
  
    // Main method
    def main(args:Array[String])
    {
      
        // Applying hashCode method
        val result = " ".hashCode()
          
        // Displays output
        println(result)
          
    }


Output:

32


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads