Scala 元组Tuple

 1 package chapter07
 2 
 3 object Test10_Tuple {
 4   def main(args: Array[String]): Unit = {
 5     // 1. 创建元组 3元祖就是有3个元素
 6     val tuple: (String, Int, Char, Boolean) = ("hello", 100, 'a', true)
 7     println(tuple)
 8 
 9     // 2. 访问数据
10     println(tuple._1)
11     println(tuple._2)
12     println(tuple._3)
13     println(tuple._4)
14 
15     println(tuple.productElement(1))
16 
17     println("====================")
18     // 3. 遍历元组数据 productIterator
19     for (elem <- tuple.productIterator)
20       println(elem)
21 
22     // 4. 嵌套元组 mulTuple._4._2
23     val mulTuple = (12, 0.3, "hello", (23, "scala"), 29)
24     println(mulTuple._4._1)
25   }
26 }

 

上一篇:学习资料记录


下一篇:更新一行逻辑update t1 set id=4;找tuple的栈