object test9 {
def main(args: Array[String]): Unit = {
val m1 = Map(
"马yun - 阿里巴巴" -> 1964,
"马化teng - 腾讯" -> 1971,
"李彦hong - 百度" -> 1968,
"雷jun - 小米" -> 1969,
"丁lei - 网易" -> 1971,
)
//常用方法:
val t = ("雷jun",1969) //元组
println(t._2)
//找出1971年出生的老板
//对于Map,可以for 遍历
//模式匹配:
for ((k,1971) <- m1){
println(k)
}
}
}
Scala模式匹配之年份匹配人名
懒惰的橘猫2024-12-05 21:38
相关推荐
与仪共舞7 小时前
罗德与施瓦茨 NRP18S|三路二极管射频功率传感器howard20054 天前
1.8.3 掌握Scala类与对象 - Scala基本骨架方法howard20055 天前
1.9 掌握Scala抽象类与特质howard20056 天前
1.8.2 掌握Scala类与对象 - 单例对象与伴生对象howard20058 天前
1.7.1 掌握Scala函数 - 声明Scala函数howard200510 天前
1.6.4 掌握Scala数据结构 - 元组howard200510 天前
1.6.5 掌握Scala数据结构 - 集合蓝眸少年CY10 天前
Scala - 基础教程howard200511 天前
1.6.3 掌握Scala数据结构 - 映射亿牛云爬虫专家11 天前
拒绝代理池雪崩:Scala + Akka 构建高并发的路由分发实战