/**
学习Tuple 元组类型
*/
object Demo {
println("Welcome to the Scala worksheet") //> Welcome to the Scala worksheet
//声明一个元组
val t1=(1,2,"hello") //> t1 : (Int, Int, String) = (1,2,hello)
val t2=(1,2,Array(3,4),List(5,6)) //> t2 : (Int, Int, Array[Int], List[Int]) = (1,2,Array(3, 4),List(5, 6))
//元组取值,通过._下标取值
//注意:元组的下标从1开始
t1._3 //> res0: String = hello
//练习1:取出t3的数字4
val t3=(1,2,(3,4)) //> t3 : (Int, Int, (Int, Int)) = (1,2,(3,4))
t3._3._2 //> res1: Int = 4
//练习2:取出t4中的数字6
val t4=(1,2,(3,4),(5,Array(6,7))) //> t4 : (Int, Int, (Int, Int), (Int, Array[Int])) = (1,2,(3,4),(5,Array(6, 7))
//| )
t4._4._2(0) //> res2: Int = 6
}
Scala学习-6.4集合类型Tuple
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- 本教程介绍了Kang等人(2017)的[https://www.nature.com/articles/nbt.4...