Skip to content
Related Articles

Related Articles

Scala String equals() method with example
  • Last Updated : 03 Oct, 2019

The equals() method is utilized to check if the stated string and object are equal.

Method Definition: Boolean equals(Object anObject)
Return Type: It returns true if the string is same as the object stated else it returns false.

Example #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)
      
    }
Output:
true

Example #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)
      
    }
Output:
false



My Personal Notes arrow_drop_up
Recommended Articles
Page :