AutoBoxing and UnBoxing

This concept is introduced in java1.5. This is introduced instread of wrapper class.

The main disadvantage of wrapper class is unnecessary conversions are required and it increases the size of the program.

In java1.5 java people concentrate on reducing the size of the program and improving the performance also.

AutoBoxing means conversion from primary to Object.

Unboxing means conversion from Object  to primary.

Example:

AutoBox.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
 
public class AutoBox {
 
    public static void main(String args[]) {
 
        Integer iobj = 100;  //autoboxing
 
        int i = iobj;          //unboxing
 
        System.out.println("the value of i is " + i);
 
        System.out.println("the value of iobj is " + iobj);
 
    }
}

 

Last modified: Monday, 19 March 2012, 12:48 AM

Skip Navigation

Navigation

Skip OpenGurukulSkip Settings

Settings