flatmap:flat即压扁,压平,扁平化,效果就是将集合中的每个元素的子元素映射到某个函数并返回新的集合
object hs {
def main(args: Array[String]): Unit = {
val names = List("Alice", "Bob", "Nick")
def upper( s : String ) : String = {
s. toUpperCase
}
println(names.map(upper))//List(ALICE, BOB, NICK)
println(names.flatMap(upper))//List(A, L, I, C, E, B, O, B, N, I, C, K)
}
}