Scala 簡明速學05 集合-Tuple

Scala 簡明速學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的數組
        val tuples = names.zip(numbs)
        for ((name, number) <- tuples) {
            println(name, number)
        }
    }
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章