×

Scala Tutorial

Scala Basics

Scala Control statements

Scala Functions

Scala Arrays

Scala Lists

Scala Strings

Scala Classes & Objects

Scala Collections

Scala String equalsIgnoreCase() Method

By IncludeHelp Last updated : October 21, 2024

Description and Usage

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!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.