Is there a built-in Java method to box an array?
问题 Is there a standard method I can use in place of this custom method? 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; } 回答1: No, there is no such method in the JDK. As it's often the case, however, Apache Commons Lang provides such a method. 回答2: Enter Java 8, and you can do following (boxing): int [] ints = ... Integer[] boxedInts = IntStream.of(ints).boxed().toArray(Integer[]: