Skip to content
Related Articles

Related Articles

Scala String intern() method with example
  • Last Updated : 03 Oct, 2019

The intern() method is utilized to check the canonical presentation of the string object.

Method Definition: String intern()
Return Type: It returns the canonical presentation of the string object.

Example: 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)
      
    }
Output:
GeeksforGeeks,
A CS portal.

Example: 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)
      
    }
Output:
My name is Nidhi,
i am an author.



My Personal Notes arrow_drop_up
Recommended Articles
Page :