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 }
复制代码

 

posted @   靠谱杨  阅读(69)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
历史上的今天:
2021-01-19 Android开发入门

喜欢请打赏

扫描二维码打赏

了解更多

点击右上角即可分享
微信分享提示