Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

Scala String equals() method with example

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

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
Last Updated : 03 Oct, 2019
Like Article
Save Article
Similar Reads