toArray()方法用於顯示Scala映射中的數組。
函數定義: def toArray: Array[(A, B)]
返回類型: It returns an array from the stated map.
範例1:
// Scala program of toArray()
// 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 toArray method
val result = m1.toArray
for ( m5 <-result )
{
println(m5 )
}
}
}
輸出:
(3,geeks) (4,for)
範例2:
// Scala program of toArray()
// 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 toArray method
val result = m1.toArray
for ( m5 <-result )
{
// Display output
println(m5 )
}
}
}
輸出:
(3,geeks) (4,for) (2,cs)
相關用法
- Scala Set toArray()用法及代碼示例
- Scala TreeSet toArray()用法及代碼示例
- Scala Queue toArray()用法及代碼示例
- Scala SortedSet toArray()用法及代碼示例
- Scala Iterator toArray()用法及代碼示例
- Scala Stack toArray()用法及代碼示例
- Scala SortedMap toArray()用法及代碼示例
- Scala Int self()用法及代碼示例
- Scala Set contains()用法及代碼示例
- Scala Map take()用法及代碼示例
- Scala Int min()用法及代碼示例
- Scala Int until(end: Int)用法及代碼示例
- Scala map()用法及代碼示例
注:本文由純淨天空篩選整理自nidhi1352singh大神的英文原創作品 Scala Map toArray() method with example。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。