我可以用一种标准方法代替这种自定义方法吗?
public static Byte[] box(byte[] byteArray) {
Byte[] box = new Byte[byteArray.length];
for (int i = 0; i < box.length; i++) {
box[i] = byteArray[i];
}
return box;
}
Run Code Online (Sandbox Code Playgroud)
YoY*_*oYo 17
输入Java 8,你可以执行以下操作(装箱):
int [] ints = ...
Integer[] boxedInts = IntStream.of(ints).boxed().toArray(Integer[]::new);
Run Code Online (Sandbox Code Playgroud)
然而,这仅适用于int[],long[]和double[].这不适用byte[].
您也可以轻松完成反向(拆箱)
Integer [] boxedInts = ...
int [] ints = Stream.of(boxedInts).mapToInt(Integer::intValue).toArray();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9629 次 |
| 最近记录: |