带有示例的 Scala String hashCode() 方法
hashCode()方法用于查找指定字符串的哈希码。
Method Definition: int hashCode()
Return Type: It returns an integer hash code of the string given.
示例 #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)
}
}
输出:
75262122
示例 #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)
}
}
输出:
32