当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Scala String contentEquals()用法及代码示例


contentEquals()方法用于将字符串与StringBuffer的内容进行比较。

函数定义: Boolean contentEquals(StringBuffer sb)
返回类型: It returns true if the content is equal to the stated string else it returns false.

范例1:


// Scala program of contentEquals() 
// method 
  
// Creating object 
object GfG 
{  
  
    // Main method 
    def main(args:Array[String]) 
    { 
        // Creating a StringBuffer 
        val m1=new StringBuffer("Nidhi") 
          
        // Applying contentEquals() method 
        val result = "Nidhi".contentEquals(m1) 
          
        // Displays output 
        println(result) 
      
    } 
} 
输出:
true

范例2:

// Scala program of contentEquals() 
// method 
  
// Creating object 
object GfG 
{  
  
    // Main method 
    def main(args:Array[String]) 
    { 
        // Creating a StringBuffer 
        val m1=new StringBuffer("Nidhi") 
          
        // Applying contentEquals() method 
        val result = "nidhi".contentEquals(m1) 
          
        // Displays output 
        println(result) 
      
    } 
} 
输出:
false


相关用法


注:本文由纯净天空筛选整理自nidhi1352singh大神的英文原创作品 Scala String contentEquals() method with example。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。