数组:

val array = new Array[Int](4) //数组的声明
array(0) = 1
array(0) = 100 //数组的长度不可变,内容可变

map

将数组中的每个元素进行某种映射操作

 val array = Array[Int](2,3,5,6,7)
 //使用
 val y = array.map((x:Int) => x*2)
  array.map(_*2)

flatten

扁平化操作

 val arr = Array("hello h1 h2", "nihao zs lisi")
  // Array[String] = Array(hello h1 h2, nihao zs lisi)
  arr.map(_.split(" "))
 //Array[Array[String]] = Array(Array(hello, h1, h2), Array(nihao, zs, lisi))
 arr.map(_.split(" ")).flatten
 // Array[String] = Array(hello, h1, h2, nihao, zs, lisi)

flatMap

等同于 map+flatten

arr.flatMap(_.split(" "))
// Array[String] = Array(hello, h1, h2, nihao, zs, lisi)

foreach

arr.flatMap(_.split(" ")).foreach(println)

worldcount

groupby的时候 key -> 数组

val arr  = Array("hello hee hello si","si tom jetty jack")
arr.flatMap(_.split(" ")).groupBy(x => x).mapValues(_.length).toList.sortBy(x => - x._2).foreach(println)