關於J2ME數組的複製及連接操作方法
public class Arrays {
/**
* 構造函數私有,這樣可以保證只能通過:類名.靜態方法 或 類名.靜態方法 來訪問內部數據,
* 而不可以通過創建本類的對象來進行訪問
*/
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;
}
}
-
SUN國際認證試題及答案
作為一個IT工作人員,你有考過SUN認證嗎?下面yjbys小編為大家分享最新的SUN國際認證考試題及答案,希望對大家的學習有所幫助!hofthefollowingfragmentsmightcauseerrors?A.Strings="Gonewiththewind";Stringt="good";Stringk=s+t;B.Strings="Gonewiththewind";Str...
-
Sun認證考試類型
Sun在UNIX領域一直是技術上和市場佔有率的領先者;繼Java技術的推出,更成為業界的標準。所以Sun公司所舉辦的認證考試,必然成為Java和UNIX在全球信息界公認的標準。Sun推出的專業認證包括下列三種:Java認證考試關於Java方面,Sun推出四大項認證:SunCertifiedJavaProgr...
-
sun認證JSP應用開發背景及特點
JSP將網頁邏輯與網頁設計和顯示分離,支持可重用的基於組件的設計,使基於Web的應用程序的開發變得迅速和容易。下面來看yjbys小編介紹吧!JSP技術使用Java編程語言編寫類XML的tags和scriptlets,來封裝產生動態網頁的處理邏輯。網頁還能通過tags和scriptlets訪問存在...
-
Sun認證Java程序員(SCJP)考題常見陷阱集合
(1)Twopublicclassesinthesamefile.(illegal)同一個文件裏有兩個public類。(非法)(2)Mainmethodcallinganon-staticmethod.(illegal)在main(String[]args)方法內調用一個非靜態方法。(非法)(3)Methodswiththesamenameastheconstructor(s).(這種題常有)與Constr...