Page 351 - AP Computer Science A, 7th edition
P. 351

 ArrayList()
Constructs an empty list. NOTE
Each method above that has an index parameter—add, get, remove, and set—throws an IndexOutOfBoundsException if index is out of range. For get, remove, and set, index is out of range if
index < 0 || index >= size()
For add, however, it is OK to add an element at the end of the list.
Therefore index is out of range if index < 0 || index > size()
Using ArrayList<E> Example 1
//Create an ArrayList containing 0 1 4 9. List<Integer> list = new ArrayList<Integer>(); //An ArrayList is-a List
for (int i = 0; i < 4; i++)
 list.add(i ∗ i);
Integer intOb = list.get(2);
int n = list.get(3);
//example of auto-boxing
//i∗i wrapped in an Integer before insertion
//assigns Integer with value 4 to intOb.
//Leaves list unchanged.
//example of auto-unboxing
//Integer is retrieved and converted to int

















































































   349   350   351   352   353