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)
  }
}

Copyright © 尚硅谷大数据 2019 all right reserved,powered by Gitbook
该文件最后修订时间: 2018-12-06 14:31:06

results matching ""

    No results matching ""