1. 程式人生 > >Scala 字串字元處理 map & filter

Scala 字串字元處理 map & filter

object Test {
  def main(args: Array[String]): Unit = {
    val name = "Zhangsan Lisi"

    val lowerName = name.map(c => c.toLower)
    val upperName = name.map(_.toUpper)

    println(lowerName)
    println(upperName)

    val student = "Jim Green"
    println(student.filter(_!='e'))
  }
}

結果:

zhangsan lisi ZHANGSAN LISI Jim Grn