scala數組方法


序號	方法和描述
1	
def apply( x: T, xs: T* ): Array[T]
創建指定對象 T 的數組, T 的值可以是 Unit, Double, Float, Long, Int, Char, Short, Byte, Boolean。
2	
def concat[T]( xss: Array[T]* ): Array[T]
合並數組
3	
def copy( src: AnyRef, srcPos: Int, dest: AnyRef, destPos: Int, length: Int ): Unit
復制一個數組到另一個數組上。相等於 Java's System.arraycopy(src, srcPos, dest, destPos, length)。
4	
def empty[T]: Array[T]
返回長度為 0 的數組
5	
def iterate[T]( start: T, len: Int )( f: (T) => T ): Array[T]
返回指定長度數組,每個數組元素為指定函數的返回值。
以上實例數組初始值為 0,長度為 3,計算函數為a=>a+1:
scala> Array.iterate(0,3)(a=>a+1)
res1: Array[Int] = Array(0, 1, 2)
6	
def fill[T]( n: Int )(elem: => T): Array[T]
返回數組,長度為第一個參數指定,同時每個元素使用第二個參數進行填充。
7	
def fill[T]( n1: Int, n2: Int )( elem: => T ): Array[Array[T]]
返回二數組,長度為第一個參數指定,同時每個元素使用第二個參數進行填充。
8	
def ofDim[T]( n1: Int ): Array[T]
創建指定長度的數組
9	
def ofDim[T]( n1: Int, n2: Int ): Array[Array[T]]
創建二維數組
10	
def ofDim[T]( n1: Int, n2: Int, n3: Int ): Array[Array[Array[T]]]
創建三維數組
11	
def range( start: Int, end: Int, step: Int ): Array[Int]
創建指定區間內的數組,step 為每個元素間的步長
12	
def range( start: Int, end: Int ): Array[Int]
創建指定區間內的數組
13	
def tabulate[T]( n: Int )(f: (Int)=> T): Array[T]
返回指定長度數組,每個數組元素為指定函數的返回值,默認從 0 開始。
以上實例返回 3 個元素:
scala> Array.tabulate(3)(a => a + 5)
res0: Array[Int] = Array(5, 6, 7)
14	
def tabulate[T]( n1: Int, n2: Int )( f: (Int, Int ) => T): Array[Array[T]]
返回指定長度的二維數組,每個數組元素為指定函數的返回值,默認從 0 開始。

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM