Scala 字符串 hashCode()方法及示例

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

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程