Java-Autoboxing and Unboxing

Autoboxing and Unboxing

Autoboxing is the process by which a primitive type is automatically encapsulated(boxed) into its equivalent type wrapper whenever an object of that type is needed. There is no need to explicitly construct an object.

Auto-unboxing is the process by which the value of a boxed object is automatically extracted (unboxed) from a type wrapper when its value is needed. There is no need to call a method such as intValue( ) or doubleValue( ).



Program Source

public class Javaapp {

    public static void main(String[] args) {
        Integer data1 = new Integer(100);
        Integer data2 = 200;
        int data3 = new Integer(300);
        System.out.println("data1 = "+data1);
        System.out.println("data2 = "+data2);
        System.out.println("data3 = "+data3);

Leave a Comment