Scala String intern() method with example

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#

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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)
      
    }

chevron_right


Output:

GeeksforGeeks,
A CS portal.

Example: 2#

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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)
      
    }

chevron_right


Output:

My name is Nidhi,
i am an author.



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.