In Java 5.0, values of primitive types such as int, double, and char can be added to collections without first having to wrap them in the corresponding wrapper objects. Java now automatically wraps values upon insertion and unwraps them upon retireval by processes known as autoboxing and unboxing. For example, the following code segment creates a list of integers, adds the integers from 1 through 10 to the list, and then increments them in place:
// Still have to use the wrapper class for the element type List<Integer> list = new ArrayList<Integer>(); // Insert just the ints for (int i = 0; i < 10; i++) list.add(i + 1); // Retrieve as an int and replace as an int for (int i = 0; i < list.size(); i++) list.set(list.get(i) + 1);