我正在开发一个使用copyOfRange(byte[] original, int start, int end)
中的Arrays.copyOfRange()
方法的应用。
仅针对API 9及更高版本引入。但是,我已经阅读了内部使用{1}}的内容,它已经在API 1中引入。
我的问题是,在Android中,使用System.arraycopy()
或Arrays.copyOfRange()
是否存在差异,如果我能够使用System.arraycopy(),它是否适用于较低版本的API ???
另外,如果我可以使用System.arraycopy()
获取一些关于复制byteArray的示例代码。
问候。
答案 0 :(得分:20)
Arrays.copyOfRange()只是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;
}
}