오토 박싱 & 오토 언박싱

Namlulu·2022년 3월 14일
0

JAVA

목록 보기
1/2
// 오토 박싱
int i = 10;
Integer num = i;

// 오토 언박싱
Integer num = new Integer(10);
int i = num;
public static void main(String[] args) {
    long t = System.currentTimeMillis();
    long sum = 0L;
    for (long i = 0; i < 1000000; i++) {
        sum += i;
    }
    System.out.println("실행 시간: " + (System.currentTimeMillis() - t) + " ms") ;
}

// 실행 시간 : 4 ms

=> 오토박싱은 wrapper클래스로 감싸는 작업이다. 같은 클래스로 연산을 해야 빠르게 된다.

profile
Better then yesterday

0개의 댓글