Scala 字符串toString()方法及示例
toString()方法是用来返回一个字符串对象本身的。
方法定义。String toString()
返回类型。它返回字符串对象。
例子: 1#
// Scala program of toString()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Applying toString method
val result = "GEEKS".toString()
// Displays output
println(result)
}
}
输出。
GEEKS
例如:2#
// Scala program of toString()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Applying toString method
val result = "10".toString()
// Displays output
println(result)
}
}
输出。
10
极客教程