본문 바로가기
Java/Stream 예제

[Stream] int[] ↔ Integer[] 변환

by Dev_Green 2023. 3. 8.

int[] → Integer[]

public static void main(String[] args) {
        int[] intArray = {1, 2, 3, 4};
        Integer[] IntArray = Arrays.stream(intArray)
                .boxed()
                .toArray(Integer[]::new);
    }

 

 Integer[] → int[]

public static void main(String[] args) {
        Integer[] IntArray = {1, 2, 3, 4};
        int[] intArray = Arrays.stream(IntArray)
                .mapToInt(i -> i)
                .toArray();
}