Scala String equals() 方法与示例
equals()方法用于检查指定的字符串和对象是否相等。
Method Definition: Boolean equals(Object anObject)
Return Type: It returns true if the string is same as the object stated else it returns false.
示例 #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