Scala Map toSeq()方法及其示例
toSeq()方法用于显示ScalaMap中的序列。
方法定义:def toSeq: Seq[A]
返回类型:它从给定的映射中返回一个序列。
示例#1:
// Scala program of toSeq()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating a map
val m1 = Map(3 -> "geeks", 4 -> "for", 4 -> "for")
// Applying toSeq method
val result = m1.toSeq
// Displays output
println(result)
}
}
ArrayBuffer((3, geeks), (4, for))
示例#2:
// Scala program of toSeq()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating a map
val m1 = Map(3 -> "geeks", 4 -> "for", 2 -> "cs")
// Applying toSeq method
val result = m1.toSeq
// Displays output
println(result)
}
}
ArrayBuffer((3, geeks), (4, for), (2, cs))
阅读更多:Scala 教程
极客教程