feat:ChatGPT第 8 课:flatMap 和嵌套集合。

This commit is contained in:
2026-09-14 14:23:23 +08:00
parent f750979b82
commit 9fe77af485
12 changed files with 274 additions and 0 deletions
@@ -0,0 +1,20 @@
package practise8.demo
/*
* split + flatMap 拆分字符串*/
object Demo5SplitFlatMap {
def main(args: Array[String]): Unit = {
val sentences = List(
"hello scala",
"hello spark"
)
// 使用map
val result = sentences.map(x => x.split(" ").toList)
println(result)
// 使用flatMap
val result2 = sentences.flatMap(x => x.split(" "))
println(result2)
}
}