Autoboxing in java is the ability to convert or cast between object wrapper and it's primitive type.
This is the actual implementation(without autoboxing)
public class OldVersion {
public static void main(String[] args) {
ArrayList list_1 = new ArrayList();
for(int i = 0; i < 10; i++){
list_1.add(new Integer(i));
}
}
The new version(with autoboxing)
public class NewVersion {
public static void main(String[] args) {
ArrayList<Integer> list_1 = new ArrayList<Integer>();
for(int i = 0; i < 10; i++){
list_1.add(i);
}
}
}
This is the actual implementation(without autoboxing)
public class OldVersion {
public static void main(String[] args) {
ArrayList list_1 = new ArrayList();
for(int i = 0; i < 10; i++){
list_1.add(new Integer(i));
}
}
The new version(with autoboxing)
public class NewVersion {
public static void main(String[] args) {
ArrayList<Integer> list_1 = new ArrayList<Integer>();
for(int i = 0; i < 10; i++){
list_1.add(i);
}
}
}
No comments:
Post a Comment