«
^
»
5.2 Storing an int in an ArrayList
Suppose you want to store integers in an
ArrayList
.
Values of type
int
are not objects.
So, until now, it has been more tricky to store
int
s in a
List
.
You can create an object of type
java.lang.Integer
from an
int
and use that:
0169: int tNumber = 123; 0170: Integer tWrapper = new Integer(tNumber); 0171: tList.add(tWrapper);
This process is known as
boxing
.