【发布时间】:2016-04-13 00:28:25
【问题描述】:
我正在使用数组缓冲区创建可变长度数组。
import scala.collection.mutable.ArrayBuffer
val b = ArrayBuffer[Int]() // empty array!
b += (1, 2, 3, 5) // append and output: ArrayBuffer(1, 2, 3, 5)
现在我想将变量 b 分配给 a
var a = Array[Int]() // a(0) = 10 // error because a is empty array
a = b.toArray // Array(1, 1, 2)
反之,如果我想将Buffer分配给一个新的变量c,就会出错。
var c = ArrayBuffer[Int]()
c = a.toBuffer // Conversely, convert the array a to an array buffer.
<console>:8: error: missing arguments for method apply in class GenericCompanion; follow this method with `_' if you want to treat it as a partially applied function
var c = ArrayBuffer[Int]
【问题讨论】:
标签: arrays scala arraybuffer