13.6 匹配列表
package com.atguigu.day11.moshipipei
object MatchList {
def main(args: Array[String]): Unit = {
val arr: List[Int] = List(1, 2, 3, 5, 6)
val res = arr match {
//case List(1, 2) => "List(1, 2)"
//case List(1, _*) => "匹配以 1 开头的列表"
//case 1 :: 2 :: 3 :: Nil => "匹配List(1,2,3)"
case 1 :: abc => println(abc); "匹配以 1 开头的列表"
case _ => "啥也可没有匹配到"
}
println(res)
}
}