Take the 2-minute tour ×

In Java, how do I take a byte[] array and remove the first 16 bytes from the array? I know I might have to do this by copying the array into a new array. Any examples or help would be appreciated.

share|improve this question
just take from byteArray[2] to byteArray[byteArray.length-1] –  Pablo Fernandez Sep 20 '11 at 3:20
Did you notice the inconsistency between your title and the question? Is it 16 bits or 16 bytes? –  Jim Garrison Sep 20 '11 at 3:23

2 Answers 2

up vote 14 down vote accepted

There's already a method for this in the Java library:

Arrays.copyOfRange(byte[] original, int from, int to)
share|improve this answer
byte[] a;


if(a.length > 1) {
    byte[] newA = new byte[a.length-2];
    for(int i = 2; i < a.length; ++i)
share|improve this answer

Your Answer


