📜  Scala Char compare() 方法与示例

📅  最后修改于: 2022-05-13 01:54:22.381000             🧑  作者: Mango

Scala Char compare() 方法与示例

compare()方法用于将指定的字符值与参数列表中的值进行比较。

示例: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