标签:有一个 元素 键值对 str uil command imp 操作 http
//1.定长数组 val arr1 = new Array[Int](10) //不定义[Int] 默认为 [Nothing] println(arr1.mkString(",")) val arr2 = Array(1, 2, 3) println(arr2.mkString(",")) arr2.apply(1) //赋值 arr2(1) = 10 //等价于 arr2.update(1, 10) println(arr2.mkString(",")) //追加 val arr3 = arr1 :+ "??" val arr4 = "??" :+ arr1 println(arr3.mkString(", "))
//2.变长数组 //小括号可以存放初始化的元素内容 val arrBuffer1 = ArrayBuffer[Int](10, 9, 8) val arrBuffer2 = ArrayBuffer[Int]() //小括号中指定的元素 println(arrBuffer1) //ArrayBuffer(10, 9, 8) 直接打印的是数组 println(arrBuffer2) //ArrayBuffer() println(arrBuffer1.mkString(",")) //10,9,8 //赋值,取值 arrBuffer1(1) = -1 println(arrBuffer1) //ArrayBuffer(10, -1, 8) println(arrBuffer1(1)) //-1 println(arrBuffer1.apply(2)) //8 //追加 arrBuffer1.append(1, 2, 3) println(arrBuffer1) //ArrayBuffer(10, -1, 8, 1, 2, 3) val arrBuffer3 = arrBuffer1 :+ 90 println(arrBuffer1) //ArrayBuffer(10, -1, 8, 1, 2, 3) println(arrBuffer3) //ArrayBuffer(10, -1, 8, 1, 2, 3, 90)
for (i <- 0 until a.length) println(i + ": " + a(i)) for (elem <- a) println(elem)
ArrayBuffer = Array.toBuffer
Array = ArrayBuffer.toArray
val matrix = Array.ofDim[Double](3, 4)
赋值:
matrix(row)(column) = 17.29
import scala.collection.JavaConverters._ import scala.collection.mutable.ArrayBuffer val command = ArrayBuffer("ls", "-al", "/") val pb = new ProcessBuilder(command.asJava) // Scala to Java val cmd : Buffer[String] = pb.command().asScala // Java to Scala cmd == command
标签:有一个 元素 键值对 str uil command imp 操作 http
原文地址:https://www.cnblogs.com/LXL616/p/11108479.html