📜  带有示例的 Scala String intern() 方法

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

带有示例的 Scala String intern() 方法

intern()方法用于检查字符串对象的规范表示。

示例:1#

// Scala program of int intern()
// method
  
// Creating object
object GfG
{ 
  
    // Main method
    def main(args:Array[String])
    {
      
        // Applying intern method
        val result = "GeeksforGeeks, \n\tA CS portal.".intern()
          
        // Displays output
        println(result)
      
    }
} 
输出:
GeeksforGeeks,
A CS portal.

示例:2#

// Scala program of int intern()
// method
  
// Creating object
object GfG
{ 
  
    // Main method
    def main(args:Array[String])
    {
      
        // Applying intern method
        val result = "My name is Nidhi, \ni am an author.".intern()
          
        // Displays output
        println(result)
      
    }
} 
输出:
My name is Nidhi,
i am an author.