0
我使用数组缓冲区创建可变长度数组。如何将ArrayBuffer分配给scala中的变量值
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相反分配给
var a = Array[Int]() // a(0) = 10 // error because a is empty array
a = b.toArray // Array(1, 1, 2)
,如果我想缓冲区分配到一个新的变量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]