2018-09-25

一、scala中两种方法定义

1、val func = (x:Int,y:Int) => x*y

2、val func2 : (Int,Int) => Int ={x*y}

二、wordcount

cmd:

val lines = List("hello tom hello jerry", "hello jerry", "hello kitty")

lines.flatMap(_.split(" ")).map((_, 1)).groupBy(_._1).mapValues(_.foldLeft(0)(_+_._2))

lines.flatMap(_.split(" ")).map((_, 1)).groupBy(_._1).map(t=>(t._1, t._2.size)).toList.sortBy(_._2).reverse

你可能感兴趣的:(2018-09-25)