带有示例的 Scala String toString() 方法
toString()方法用于返回字符串对象本身。
Method Definition: String toString()
Return Type: It returns the string object.
示例: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