Scala Char compare() method with example
Last Updated :
03 Nov, 2019
The compare() method is utilized to compare the stated character value with the value in the arguments list.
Method Definition: def compare(y: Char): Int
Return Type: It returns Int. Where, if the stated character value is greater than ‘x’ then a positive integer is returned, if its less than ‘x’ then a negative integer is returned and if its equal to ‘x’ then zero is returned.
Example: 1#
object GfG
{
def main(args : Array[String])
{
val result = 'a' .compare( 'A' )
println(result)
}
}
|
Example: 2#
object GfG
{
def main(args : Array[String])
{
val result = 'B' .compare( 'B' )
println(result)
}
}
|
Share your thoughts in the comments
Please Login to comment...