compare()方法用于将指定的字符值与参数列表中的值进行比较。
函数定义: def compare(y: Char): Int
返回类型: 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 compare()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Applying compare() method
val result = 'a'.compare('A')
// Displays output
println(result)
}
}
输出:
32
示例:2#
// Scala program of compare()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Applying compare() method
val result = 'B'.compare('B')
// Displays output
println(result)
}
}
输出:
0
相关用法
- Scala Char to(end: Char, step: Char)用法及代码示例
- Scala Int compare()用法及代码示例
- Scala Float compare()用法及代码示例
- Scala Int Compare用法及代码示例
- Scala Char to(end: Char)用法及代码示例
注:本文由纯净天空筛选整理自nidhi1352singh大神的英文原创作品 Scala Char compare() method with example。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。