Scala String equals() method with example
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 objectobject 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 objectobject 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


