Scala 字符串 intern()方法与实例
利用 intern() 方法来检查字符串对象的典范表现。
方法定义。String intern()
返回类型。它返回字符串对象的典型表现形式。
例子: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.
极客教程