Home »
Scala
Scala String hashCode() Method with Example
Here, we will learn about the hashCode() method of String class in Scala. It is used to find the hash code for the given string. We will see its working, syntax and example.
Submitted by Shivang Yadav, on February 03, 2021
String is an immutable collection that stores sequences of characters.
String hashCode() Method
The hashCode() method on strings is used to return the hash code for the given string in Scala.
Syntax:
string_Name.hashCode()
Parameters: The method is a parameter-less method i.e. it does not accept any parameter.
Return Value: It returns an integer which is the hash code for the given string in Scala.
Example 1:
object myObject {
def main(args: Array[String]) {
val string1 = "scala"
val hash = string1.hashCode()
println("The hash code for the string is " + hash)
}
}
Output:
The hash code for the string is 109250886