带有示例的 Scala List mkString() 方法
mkString()方法用于在字符串中显示列表的所有元素。
Method Definition: def mkString: String
Return Type: It returns all the elements of the list in a string.
示例 #1:
// Scala program of mkString()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating a list
val m1 = List(2, 3, 5, 7, 8)
// Applying mkString method
val result = m1.mkString
// Displays output
println(result)
}
}
输出:
23578
示例 #2:
// Scala program of mkString()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating a list
val m1 = List(2, 3, 5, 7, 5)
// Applying mkString method
val result = m1.mkString
// Displays output
println(result)
}
}
输出:
23575