gpt4 book ai didi

java - ByteBuffer 到 int 数组(每个字节)

转载 作者:行者123 更新时间:2023-12-02 05:08:51 34 4
gpt4 key购买 nike

与问题相关byte array to Int Array ,但是我想将每个字节转换为 int,而不是每个 4 字节。

还有比这更好/更干净的方法吗:

protected static int[] bufferToIntArray(ByteBuffer buffer) {
byte[] byteArray = new byte[buffer.capacity()];
buffer.get(byteArray);

int[] intArray = new int[byteArray.length];

for (int i = 0; i < byteArray.length; i++) {
intArray[i] = byteArray[i];
}

return intArray;
}

最佳答案

我可能更喜欢

int[] array = new int[buffer.capacity()];
for (int i = 0; i < array.length; i++) {
array[i] = buffer.get(i);
}
return array;

关于java - ByteBuffer 到 int 数组(每个字节),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27516204/

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