在下面的API 9中使用Arrays.copyOfRange()

时间:2013-04-22 07:10:10

标签: java android

我正在开发一个使用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的示例代码。

问候。

1 个答案:

答案 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;
    }
}