Scala Tips

Reason is the light and the light of life.

Jerry Su Jul 17, 2019 1 mins
  • foreach
val xs = List("date", "since", "other1", "other2")

xs.foreach { str =>

    str match {
        case "date"  => println("Match Date")
        case "since" => println("Match Since")
        case unknow  => println("Others")
    } 

    println("Put your post step here")
}

注意:如果要使用一段代码作为foreach()的参数,则应使用{}而不是()。


Read more:

Related posts: