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)
原文:https://www.cnblogs.com/feifeicui/p/10963899.html