Java automatically convert primitive types in to corresponding wrapper class is called autoboxing and converting wrapper class in to primitive types called unboxing. This feature introduced in java 1.5
Example
package com.vinod.test;
import java.util.ArrayList;
import java.util.List;
public class AutoBoxing {
public static void main(String[] args) {
List<Integer> list = new ArrayList();
list.add(1); // Autoboxing
list.add(2);
int a = list.get(0);// unboxing
int b = list.get(1);
System.out.println("value of a " + a + "value of b" + b);
}
}
import java.util.ArrayList;
import java.util.List;
public class AutoBoxing {
public static void main(String[] args) {
List<Integer> list = new ArrayList();
list.add(1); // Autoboxing
list.add(2);
int a = list.get(0);// unboxing
int b = list.get(1);
System.out.println("value of a " + a + "value of b" + b);
}
}
No comments:
Post a Comment