Big Data learning --scala small example of wordCount

 val lines = List("hello tom hello jerry", "hello jerry", "hello kitty")
    println("---word"+lines.flatMap(_.split(" ")).map((_,1)).groupBy(_._1).map(t=>(t._1,t._2.size)))
    println("---word"+lines.flatMap(_.split(" ")).map((_,1)).groupBy(_._1).map(t=>(t._1,t._2.size)).toList.sortBy(_._2))
    println("---word"+lines.flatMap(_.split(" ")).map((_,1)).groupBy(_._1).map(t=>(t._1,t._2.size)).toList.sortBy(_._2).reverse)
   

 

Guess you like

Origin www.cnblogs.com/feifeicui/p/10963899.html