首页 > 代码库 > scala数组

scala数组

#scala数组

val A= new Array[T](N) val A = new Array[Int](10)

 

##变长数组

import scala.collection.mutable.ArrayBuffer

val C = new ArrayBuffer[T]()

C += e1

C += (e2,e3)

C++ = Array(e2,e3)

trimEnd(2)  #移除最后2个

C.insert(2,e3)

C.remove(3,2)

 

#转换

D=C.toArray    #变长->定长   

E=A.toBuffer   #定长->变长

#数组遍历

for(i <- C) print ln(i)

for(i <- 0 to (C.length-1)) print (C(i))

for(i<- 0 to (C.length-1,2)) print (C(i)) 每两个输出一个

for ( i <- (0 to C.length).reverse)println(C(i))

 

scala数组