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