Scala Set mkString() 方法与示例
mkString()方法用于在字符串中显示集合的所有元素。
Method Definition: def mkString: String
Return Type: It returns a string containing all the element of the set.
示例 #1:
// Scala program of mkString()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating a set
val s1 = Set(1, 2, 3, 4)
// Applying mkString method
val result = s1.mkString
// Display output
println(result)
}
}
输出:
1234
示例 #2:
// Scala program of mkString()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating a set
val s1 = Set("Geeks", "Will", "Rule")
// Applying mkString method
val result = s1.mkString
// Display output
println(result)
}
}
输出:
GeeksWillRule