Java/Stream 예제
[Stream] int[] ↔ Integer[] 변환
Dev_Green
2023. 3. 8. 22:35
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();
}