티스토리 뷰
wrapper class
the primitive data type is not an object, so If we need a method that only takes objects as a parameter, it can't be used. Therefore, wrapper classes are used to convert data type into an object.
Primitive Data Type |
Wrapper instance |
char |
Character |
byte |
Byte |
short |
Short |
long |
Integer |
float |
Float |
double |
Double |
boolean |
Boolean |
Boxing & UnBoxing
The conversion of primitive data types into wrapper class is boxing. Whereas, converting an object into corresponding primitive data type is unboxing
Example code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | public class BoxingUnBoxing { public static void main(String[] args) { Integer iValue = new Integer(10); Double dValue = new Double(3.14); System.out.println(iValue); //10 System.out.println(dValue); //3.14 iValue = new Integer(iValue.intValue()+10); dValue = new Double(dValue.doubleValue()+1.2); System.out.println(iValue); //20 System.out.println(dValue); //4.34 } } | cs |
AutoBoxing & AutoUnBoxing
Example code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | public class AutoBoxingUnBoxing { public static void main(String[] args) { Integer iValue = 10; //auto boxing Double dValue = 3.14; // aut boxing System.out.println(iValue); //10 System.out.println(dValue); //3.14 int num1 = iValue; //auto unboxing double num2 = dValue; //auto unboxing System.out.println(num1); //10 System.out.println(num2); //3.14 } } | cs |
'JAVA' 카테고리의 다른 글
abstract & Interface in java (0) | 2019.01.17 |
---|---|
toString method (0) | 2019.01.08 |
String methods in Java (0) | 2019.01.07 |
Java Generics (runtime error,compile error) (0) | 2019.01.06 |
static in Java (0) | 2019.01.05 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- C++
- 알고리즘
- Javascript Algorithm
- math.max
- substring()
- 프로그래머스
- ... in Javascript
- javascript
- math.abs
- equals()
- hackerrank
- string class in java
- easy javascript algorithm
- code refactoring
- easy algorithm
- hackerrank solution
- spring boot application
- 프로그래머스 알고리즘
- Object type casting
- compareTo()
- Collection Framework
- algorithm
- repeat()
- hackerrank javascript
- 프로그래머스 알고리즘문제
- rest parameter
- java
- HashMap
- HackerRank Algorithm
- hackerrank javascript solution
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 | 31 |
글 보관함