带有示例的 Scala String intern() 方法
intern()方法用于检查字符串对象的规范表示。
Method Definition: String intern()
Return Type: It returns the canonical presentation of the string object.
示例: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)
}
}
输出:
GeeksforGeeks,
A CS portal.
示例: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)
}
}
输出:
My name is Nidhi,
i am an author.