DT Big Data Dream Factory 5th lecture http://yun.baidu.com/s/1jGjFpWy This section Wang teacher spoke the array. The main thing is to use the Scala worksheet feature. This function can print out the operation of each line of code. Package Com.dt.scala.hello
Import Scala.collection.mutable.ArrayBuffer
Object Arrayops {
def main (args:array[string]): Unit = { val nums = new Array[int] (Ten) val a = New Array[string] (Ten) val s = Array ("Hello", "World") s (0) = "Goodbye" val b = Arraybuffer[int] () B + = 1 B + = (1, 2, 3, 5) b ++= Array (8,, 2) b.trimend (5) B.insert (6,) &NBSP;&N bsp; B.insert (2, 7, 8, 9) B.remove (2) B.remove (2, 3) B.toa Rray for (i <-0 until a.length) println (i + ":" + A (i) ) val c = Array (2, 3, 5, 7, one) Val Res Ult = for (elem <-c) Yield 2 * elem for (elem <-c if elem% 2 = = 0) Yield 2 * elem C.filter (_% 2 = =0). Map (2 * _) Array (1, 7, 2, 9). Sum ArrayBuffer ("Mary", "had", "a "," little "," Lamb "). Max val d = ArrayBuffer (1, 7, 2, 9) Val bsor Ted = d.sorted val e = Array (1, 7, 2, 9) Scala.util.Sorting.quick Sort (e) e.mkstring ("and") a.mkstring ("<", ",", ">") & nbsp; val matrix = array.ofdim[double] (3, 4) Matrix (2) (1) = &NBSP;&N bsp; val triangle = new Array[array[int] (Ten) for (i <-0 until triangle.length) & nbsp; triangle (i) = new Array[int] (i + 1) }
}
DT Big Data Dream Factory 5th Talk