Open In App

Scala String intern() method with example

Last Updated : 03 Oct, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

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.


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads