# Auto-boxing and (auto)Unboxing

Auto-boxing : primitive type=>object\
Unboxing : object=>primitive type

```java
ArrayList<Integer> list = new ArrayList<Integer>();
//only object is possible but compiler does automatically
list.add(10);//list.add(new Integer(10));

int value = list.get(0);//list.get(0).intValue()
```

intValue(), valueOf() : Integer -> int

```java
int i = 10;

//기본형을 참조형으로 형변환(형변환 생략가능)
Integer intg = (Integer)i;//Integer intg = Integer.valueOf(i);
Object obj = (Object)i;//Object obj = (Object)Integer.valueOf(i);

//참조형 변수
Long lng = 100L;//Long lng = new Long(100L);

//참조형과 기본형간의 연산 가능
int i2 = intg + 10;
//참조형간의 덧셈도 가능
long l = intg + lng;

Integer intg2 = new Integer(20);
int i3 = (int)intg2;//참조형을 기본형으로 형변환도 가능(형변환 생략가능)


```

\ <br>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://heunnajo.gitbook.io/java/java.lang-package-and-useful-class/auto-boxing-and-auto-unboxing-1.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
