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!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.