带有示例的 Scala Char compareTo() 方法
compareTo()方法用于将规定的字符值与参数列表中的值进行比较。与比较方法相同。
Method Definition: def compareTo(arg0: Character): 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.
示例:1#
// Scala program of compareTo()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Applying compareTo() method
val result = 'a'.compareTo('A')
// Displays output
println(result)
}
}
输出:
32
示例:2#
// Scala program of compareTo()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Applying compareTo() method
val result = 'B'.compareTo('B')
// Displays output
println(result)
}
}
输出:
0