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))

原文地址:https://www.cnblogs.com/djh222/p/11994508.html