gpt4 book ai didi

java - 在 API 9 以下使用 Arrays.copyOfRange()

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:35:01 26 4
gpt4 key购买 nike

我正在开发一个应用程序,它使用 Arrays.copyOfRange() 中的方法 copyOfRange(byte[] original, int start, int end)

它仅在 API 9 及更高版本中引入。但是,我在某处读到它在内部使用了 API 1 本身引入的 System.arraycopy()

我的问题是,在 Android 中,使用 Arrays.copyOfRange()System.arraycopy() 是否有区别,如果我能够使用 System. arraycopy() 是否适用于较低版本的 API???

此外,如果我能获得一些使用 System.arraycopy() 复制 byteArray 的示例代码。

问候。

最佳答案

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

关于java - 在 API 9 以下使用 Arrays.copyOfRange(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16141334/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com