Scala 字符串 hashCode()方法及示例
hashCode() 方法用于查找所述字符串的哈希代码。
方法定义:int hashCode()
返回类型。它返回给定字符串的整数哈希代码。
例子 #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
极客教程