import org.apache.spark.{SparkConf, SparkContext} import org.apache.spark.sql.SparkSession object WordCount { def main(args:Array[String]): Unit ={ val conf = new SparkConf() .setAppName("WordCount"); val sc = new SparkContext(conf) val lines =…
val lines=List("hello tom hello jerry","hello tom hello kitty hello china") //方法一: val wc=lines.flatMap(_.split(" ")).map((_,1)).groupBy(_._1).map(t=>(t._1,t._2.size)).toList.sortBy(_._2).reverse //方法二: val wc2=lines.flatM…