Scala String compareToIgnoreCase() method with example
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 m 1 = "Nidhi" // Applying compareToIgnoreCase() method val result = m 1 .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 m 1 = "Nidhi" // Applying compareToIgnoreCase() method val result = m 1 .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 m 1 = "Nidhi" // Applying compareToIgnoreCase() method val result = m 1 .compareToIgnoreCase( "NiDh" ) // Displays output println(result) } } |
Output:
1