Scala 簡明速學(xué)05 集合-Tuple
Tuple
Scala中Tuple為單個鍵值對。
object TupleTest {
def main(args: Array[String]): Unit = {
val t = ("Lebron" -> 23)
println(t._1, t._2) //訪問key和value
//zip操作
val names = Array("Lebron", "Rondo", "Ball")
val numbs = Array(23, 9, 0)
//返回一個元素類型為tuple的數(shù)組
val tuples = names.zip(numbs)
for ((name, number) <- tuples) {
println(name, number)
}
}
}