Friday, August 9, 2013

AutoBoxing and unboxing in java 1.5 features


AutoBoxing and Unboxing in Java 1.5 version



                              Autometic convension of primitive data types to wrapper type is Autoboxing. The opposite operation is known as unboxing. 
                                In jdk 1.4 conversion between wrapper object and primitive type should be done manually.
                                Now in jdk 1.5 it becomes more easier to do the conversion using Autobboxing.

To learn more on autoboxing and unboxing  java training in chennai or java tutorial by candid

Example 1 Auto Boxing

import java.util.*;

public class AutoBoxExample {

    public static void main(String args[]) {
        int a = 50;
        Integer a2 = new Integer(a);// Boxing

        Integer a3 = 5;// Boxing

        System.out.println(a2 + " " + a3);
    }
}


Example 2 - unboxinf


class UnboxExample {
    public static void main(String args[]) {

        Integer a = new Integer(50);

        int i = a;

        System.out.println(i);
    }
}

No comments:

Post a Comment