flatMap
val lineArray = Array("hello you","hello me","hello world")
val lines = sc.parallelize(lineArray, 1)
val words = lines.flatMap(line =>{ line.split(" ") })
words.foreach {
word => println(word.mkString)
}
结果:
1.png
map
val lineArray = Array("hello you","hello me","hello world")
val lines = sc.parallelize(lineArray, 1)
val words = lines.map(line =>{ line.split(" ") })
words.foreach {
word => println(word.mkString)
}
结果
1.png
map:获取一个新元素(原本几个元素还是几个元素) flatmap 获取一个或者多个新元素(比原来的元素多)