1.定义数组: val stringList = List(“hello Aythna hello Kirito”,“hello Liliya hello luluxiu”,“hello Nana hello Sandy”)
2.压缩数组(调用flatMap方法),按空格来分割:stringList.flatMap (x => x.split(" "))
3.将分割好的数组用map方法处理:stringList.flatMap (x => x.split(" ")).map(x => (x,1))
4.将该map用数组中的key进行分组:stringList.flatMap (x => x.split(" ")).map(x => (x,1)).groupBy(x => x._1)
5.用map方法进行统计:stringList.flatMap (x => x.split(" ")).map(x => (x,1)).groupBy(x => x._1).map(x => (x._1,x._2.size))