I am developing an app which uses the method copyOfRange(byte[] original, int start, int end)
from Arrays.copyOfRange()
.
It has been introduced in only for API 9 and above. But, I have read somewhere that internally it uses System.arraycopy()
which has been introduced in API 1 itself.
My question is, in Android, is there a difference in using Arrays.copyOfRange()
or System.arraycopy()
and if I am able to use System.arraycopy() will it work for lower versions of APIs???
Also, if I could get some sample code on copying a byteArray using System.arraycopy()
.
Regards.
Arrays.copyOfRange() is just a convenience method for System.arrayCopy()
public class ArraysCompat {
public byte[] copyOfRange(byte[] from, int start, int end){
int length = end - start;
byte[] result = new byte[length];
System.arraycopy(from, start, result, 0, length);
return result;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With