Scala List addString() 方法与示例
addString()方法用于将列表的所有元素附加到字符串构建器。
Method Definition: def addString(b: StringBuilder): StringBuilder
Return Type: It returns the elements of the list to a string builder.
示例 #1:
// Scala program of addString()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating a list
val m1 = List(1, 3, 5, 2)
// Applying addString method
val res = m1.addString(new StringBuilder())
// Displays output
println(res)
}
}
输出:
1352
示例 #2:
// Scala program of addString()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating a list
val m1 = List(1, 1, 5, 2)
// Applying addString method
val res = m1.addString(new StringBuilder())
// Displays output
println(res)
}
}
输出:
1152