糯米文學吧

位置:首頁 > IT認證 > SUN認證

關於J2ME陣列的複製及連線操作方法

SUN認證2.45W

public class Arrays {

關於J2ME陣列的複製及連線操作方法

/**

* 構造函式私有,這樣可以保證只能通過:類名.靜態方法 或 類名.靜態方法 來訪問內部資料,

* 而不可以通過建立本類的物件來進行訪問

*/

private Arrays() {

}

/**

* 複製一個跟源byte陣列一樣的byte陣列

* @param rSource 源byte陣列

* @return 跟源byte[]陣列一樣的byte[]陣列

*/

static public byte[] copy(byte[] rSource) {

byte[] aResult = new byte[th];

ycopy(rSource, 0, aResult, 0, th);

return aResult;

}

/**

* 複製一個跟源int陣列一樣的int陣列

* @param rSource 源int陣列

* @return 跟源int陣列一樣的陣列

*/

static public int[] copy(int[] rSource) {

int[] aResult = new int[th];

ycopy(rSource, 0, aResult, 0, th);

return aResult;

}

/**

* 比較兩個byte陣列的內容及長度是否相等.

* @param a1 第一個byte陣列

* @param a2 第二個byte陣列

* @return 相等的話返回true,否則返回false

*/

static public boolean equals(byte[] a1, byte[] a2) {

if ( (a1 == null) || (a2 == null)) {

return a1 == a2;

}

int nLength = th;

if (nLength != th) {

return false;

}

for (int i = 0; i < nLength; i++) {

if (a1[i] != a2[i]) {

return false;

}

}

return true;

}

/**

* 比較兩個int陣列的內容及長度是否相等.

* @param a1 第一個int陣列

* @param a2 第二個int陣列

* @return 相等的話返回true,否則返回false

*/

static public boolean equals(int[] a1, int[] a2) {

if ( (a1 == null) || (a2 == null)) {

return a1 == a2;

}

int nLength = th;

if (nLength != th) {

return false;

}

for (int i = 0; i < nLength; i++) {

if (a1[i] != a2[i]) {

return false;

}

}

return true;

}

/**

* 連線兩個byte陣列,之後返回一個新的連線好的byte陣列

* @param a1

* @param a2

* @return 一個新的連線好的byte陣列

*/

static public byte[] join(byte[] a1, byte[] a2) {

byte[] result = new byte[th + th];

ycopy(a1, 0, result, 0, th);

ycopy(a2, 0, result, th, th);

return result;

}

/**

* 連線兩個int陣列,之後返回一個新的連線好的int陣列

* @param a1

* @param a2

* @return 一個新的連線好的int陣列

*/

static public int[] join(int[] a1, int[] a2) {

int[] result = new int[th + th];

ycopy(a1, 0, result, 0, th);

ycopy(a2, 0, result, th, th);

return result;

}

}