Open In App

Scala String equals() method with example

Last Updated : 03 Oct, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

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


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads