Scala String intern() Method with Example

Here, we will learn about the intern() method of String in Scala. It is used to convert the string to its standard form. We will see its working, syntax and example.
Submitted by Shivang Yadav, on February 03, 2021

String is an immutable collection that stores sequences of characters.

String intern() Method

The intern() method on strings is used to check canonical presentation of the given string. It returns the standard representation of the given string.

Syntax:

string_Name.intern()

Parameters: The method is a parameter-less method i.e., it does not accept any parameter.

Return Value: It returns a string which is a canonical presentation of the given string.

Example 1:

object myObject {
    def main(args: Array[String]) {
        val string1 = "includehelp\t is a great place to learn programming. \n They have the best programming tutorials"
        val canonicalString = string1.intern()
    
        println("The standard string is \n'" + canonicalString + "'")
    }
}

Output:

The standard string is 
'includehelp	 is a great place to learn programming. 
 They have the best programming tutorials'




Comments and Discussions




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.