Scala String equalsIgnoreCase() Method with Example

Here, we will learn about the equalsIgnoreCase() method of String class in Scala. It is used to compare string objects. We will see its working, syntax and example.
Submitted by Shivang Yadav, on February 04, 2021

String is an immutable collection that stores sequences of characters.

String equalsIgnoreCase() Method

The equalsIgnoreCase() method on strings is used to compare string and object. The method ignores cases of characters of the string while making the comparison.

Syntax:

string1_Name.equalsIgnoreCase(String string2_Name)

Parameters: The method accepts a single parameter which the other string object to be compared.

Return Value: It returns a Boolean value which is the result of the comparison operation.

Example 1:

object MyClass {
    def main(args: Array[String]) {
        val string1 = "Scala"
        val string2 = "scaLa"
        
        val is_equal = string1.equalsIgnoreCase(string2)
    
        if(is_equal)
            println("The strings are equal!")
        else 
            println("The strings are not equal!")
    }
}

Output:

The strings are equal!

Example 2:

object MyClass {
    def main(args: Array[String]) {
        val string1 = "Scala"
        val string2 = "Scala programming "
        
        val is_equal = string1.equalsIgnoreCase(string2)
        
        if(is_equal)
            println("The strings are equal!")
        else 
            println("The strings are not equal!")
    }
}

Output:

The strings are not equal!




Comments and Discussions




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.