Wrapper Classes and the ArrayList

A list that grows as values arrive is an ArrayList. It holds object references, so a list of whole numbers holds Integer objects, and Java converts between those and int values on its own. Below, an elevator records each floor a rider requests.
Wrapper classes
An int is a primitive value and isn't an object. The Integer class wraps one int in an object, and the Double class wraps one double. Both are in the java.lang package. A program can use them with no import statement.
Neither class has a method that changes the value an object holds. Assigning a wrapper variable points it at another object, and the object it pointed at before keeps its value.
Boxing and unboxing
ArrayList<Integer> floors = new ArrayList<Integer>();
floors.add(7);
floors.add(2);
floors.add(11);
int first = floors.get(0);
The call floors.add(7) passes the int 7 to a method that expects an Integer, so Java creates an Integer holding 7, a conversion called autoboxing. In the last statement get returns an Integer, which is assigned to an int variable. So Java takes out the 7, a conversion called unboxing.
Text to numbers
A rider types a floor on a keypad, and the program receives the text "4". The class method Integer.parseInt turns text into an int, and Double.parseDouble turns it into a double. So floors.add(Integer.parseInt(typed)) converts the text to the int 4, and autoboxing turns that into an Integer for the list.
The ArrayList
ArrayList is in the java.util package. A class that uses one needs an import statement at the top, either of these:
import java.util.ArrayList;
import java.util.*;
The constructor new ArrayList<Integer>() makes an empty list. The type in angle brackets is the element type, and it must be a reference type, such as a class. So the list is ArrayList<Integer> and never ArrayList<int>. Because the type is stated, the compiler checks every use: get returns an Integer, so String s = floors.get(0); doesn't compile.
An array keeps the length it was created with. Each call to add(E obj) puts its argument at the back of the list and makes the list one longer. After the three calls above, floors.size() is 3. The method get(int index) returns the element at an index, and the indexes run from 0 through floors.size() - 1. So floors.get(2) is 11, and floors.get(3) throws an IndexOutOfBoundsException.