Java
[JAVA] Wrapper class란?
YEJI ⍢
2022. 12. 27. 00:55
728x90
Wrapper class란?
Primitive type을 class type으로 포장해 주는 클래스를 말합니다.
Primitive type | Class type | Method to convert back |
int | Integer | intValue() |
long | Long | longValue() |
float | Float | floatValue() |
double | Double | doubleValue() |
char | Charactcer | charValue() |
Integer class로 예제를 살펴보겠습니다.
public static void main(String[] args) {
Integer n = new Integer(10);
System.out.println(n.intValue());
}
Primitive type의 변수에 값을 할당할 때는 간단하게 "="(assignment) 연산자를 사용하면 되지만,
class로 wrapper된 Integer class는 메소드(method)를 통해 값을 할당할 수 있습니다.
◡̈