Byte[]和byte[]的轉換

byte[] toPrimitives(Byte[] oBytes)
{
    byte[] bytes = new byte[oBytes.length];

    for(int i = 0; i < oBytes.length; i++) {
        bytes[i] = oBytes[i];
    }

    return bytes;
}
// byte[] to Byte[]
Byte[] toObjects(byte[] bytesPrim) {
    Byte[] bytes = new Byte[bytesPrim.length];

    int i = 0;
    for (byte b : bytesPrim) bytes[i++] = b; // Autoboxing

    return bytes;
}

apache commons lang librayry的ArrayUtils實現了toPrimitive方法

發佈了23 篇原創文章 · 獲贊 15 · 訪問量 11萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章