Skip to content
Related Articles

Related Articles

Scala String compareToIgnoreCase() method with example
  • Last Updated : 03 Oct, 2019

The compareToIgnoreCase() method is utilized to compare two strings like compareTo method but here the case (upper or lowercase) difference is ignored while comparing.

Method Definition:int compareToIgnoreCase(String str)
Return Type:It is same as compareTo() method but here only case difference is ignored.

Example: 1#




// Scala program of compareToIgnoreCase()
// method
  
// Creating object
object GfG
  
    // Main method
    def main(args:Array[String])
    {
        // Creating a String
        val m1 = "Nidhi"
          
        // Applying compareToIgnoreCase() method
        val result = m1.compareToIgnoreCase("Nidhi")
          
        // Displays output
        println(result)
      
    }
Output:
0

Example #2:






// Scala program of compareToIgnoreCase()
// method
  
// Creating object
object GfG
  
    // Main method
    def main(args:Array[String])
    {
        // Creating a String
        val m1 = "Nidhi"
          
        // Applying compareToIgnoreCase() method
        val result = m1.compareToIgnoreCase("NiDhi")
          
        // Displays output
        println(result)
      
    }
Output:
0

Here, also both the strings are considered same even if there is a case difference.
Example #3:




// Scala program of compareToIgnoreCase()
// method
  
// Creating object
object GfG
  
    // Main method
    def main(args:Array[String])
    {
        // Creating a String
        val m1 = "Nidhi"
      
        // Applying compareToIgnoreCase() method
        val result = m1.compareToIgnoreCase("NiDh")
      
        // Displays output
        println(result)
      
    }
Output:
1

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :