wordcount--scala

val words:Array[String]=Array("hello tom hello jim","hello hatno hello 菲菲")

words.map(x=>x.split(" "))

   .flatten

   .groupBy(x=>x)

   .map(wdKV=>(wdKV._1,wdKV._2.length))

   .toList.sortBy(t=>t._2)

   .foreach(t=>println(t))

 

 

posted @ 2019-12-06 12:02  寅狗  阅读(118)  评论(0编辑  收藏  举报