자바 Integer 배열을 int 배열로 변환

1 개요[ | ]

How to convert Integet[] to int[] in java
자바 Integer 배열을 int 배열로 변환
Java
CPU
1.6s
MEM
78M
1.4s
Copy
import java.util.Arrays;
public class MyClass {
    public static void main(String args[]) {
        Integer a[] = {1,2,3,4};
        int b[] = Arrays.stream(a).mapToInt(Integer::intValue).toArray(); 

        System.out.println( a.getClass() );        // class [Ljava.lang.Integer;
        System.out.println( Arrays.toString(a) );  // [1, 2, 3, 4]
        
        System.out.println( b.getClass() );        // class [I
        System.out.println( Arrays.toString(b) );  // [1, 2, 3, 4]
    }
}
class [Ljava.lang.Integer;
[1, 2, 3, 4]
class [I
[1, 2, 3, 4]
Java
Copy
import java.util.Arrays;
public class MyClass {
    public static void main(String args[]) {
        Integer a[] = {1,2,3,4};
        int b[] = Arrays.stream(a).mapToInt(i->i).toArray(); 

        System.out.println( a.getClass() );        // class [Ljava.lang.Integer;
        System.out.println( Arrays.toString(a) );  // [1, 2, 3, 4]
        
        
        System.out.println( b.getClass() );        // class [I
        System.out.println( Arrays.toString(b) );  // [1, 2, 3, 4]
    }
}
Loading

2 같이 보기[ | ]

3 참고[ | ]