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#
object GfG
{
def main(args : Array[String])
{
val m 1 = "Nidhi"
val result = m 1 .compareToIgnoreCase( "Nidhi" )
println(result)
}
}
|
Example #2:
object GfG
{
def main(args : Array[String])
{
val m 1 = "Nidhi"
val result = m 1 .compareToIgnoreCase( "NiDhi" )
println(result)
}
}
|
Here, also both the strings are considered same even if there is a case difference.
Example #3:
object GfG
{
def main(args : Array[String])
{
val m 1 = "Nidhi"
val result = m 1 .compareToIgnoreCase( "NiDh" )
println(result)
}
}
|
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...