Using Arrays.copyOfRange () for API API 9

I am developing an application that uses the copyOfRange(byte[] original, int start, int end) Arrays.copyOfRange() from Arrays.copyOfRange() .

It was introduced only for API 9 and above. But I read somewhere that inside it uses System.arraycopy() , which was introduced in API 1 itself.

My question in Android is whether there is a difference in using Arrays.copyOfRange() or System.arraycopy() , and if I can use System.arraycopy (), it will work for lower versions of the API.

Also, if I could get some sample code for copying an Array byte using System.arraycopy() .

Sincerely.

+4
source share
1 answer

Arrays.copyOfRange () is just a convenient 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; } } 
+20
source

All Articles