본문 바로가기
Java/Stream 예제

[Java / Stream] 배열 ↔︎ 리스트 간 변환 (정수)

by Dev_Green 2023. 2. 1.

예제 코드

int[] arr = {1, 2, 3, 4};
        
// 배열 -> 리스트
List<Integer> list = new ArrayList<>(
        Arrays.stream(arr)
                .boxed()
                .collect(Collectors.toList())
);

// 리스트 -> 배열
int[] arrB = list.stream()
                .mapToInt(i -> i)
                .toArray();