📜  Scala String equals() 方法与示例

📅  最后修改于: 2022-05-13 01:55:31.866000             🧑  作者: Mango

Scala String equals() 方法与示例

equals()方法用于检查指定的字符串和对象是否相等。

示例 #1:

// Scala program of equals()
// method
  
// Creating object
object GfG
{ 
  
    // Main method
    def main(args:Array[String])
    {
        // Creating an array
        val m1 = Array('N', 'i', 'd', 'h', 'i')
          
        // Applying equals() method
        val result = "Nidhi".equals("Nidhi")
          
        // Displays output
        println(result)
      
    }
} 
输出:
true

示例 #2:

// Scala program of equals()
// method
  
// Creating object
object GfG
{ 
  
    // Main method
    def main(args:Array[String])
    {
        // Creating an array
        val m1 = Array('N', 'i', 'd', 'h', 'i')
          
          
        // Applying equals() method
        val result = "Nidhi".equals("Nidh")
          
        // Displays output
        println(result)
      
    }
} 
输出:
false