大数据学习——scala的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)
   

猜你喜欢

转载自www.cnblogs.com/feifeicui/p/10963899.html
今日推荐