程序题,用一行代码完成装箱拆箱(用stream流完成装箱,拆箱)
Integer[] numbers = {1,2,3,4};
拆箱
//IntStream intStream = Arrays.stream(numbers).mapToInt(new ToIntFunction<Integer>() {
//@Override
//public int applyAsInt(Integer value) {
// return value.intValue();
// }
//});
int[] array = Arrays.stream(numbers).mapToInt(Integer::intValue).toArray();
装箱
Arrays.stream(array).boxed().toArray(Integer[]::new);
其他类型举一反三,例如Double
把mapToTnt
换成mapToDouble
,把Integer
换成Double
就好了