When declaring an ArrayList, the datatype stored in the container is specified inside of <>, and the data type must be the name of a class (no primitive data types)
The parameter to the method get represents the index in the ArrayList. The size of the ArrayList is the number of elements contained. If the ArrayList is initially empty, the size is 0.
Passing as argument - a copy of the reference to the instantiated ArrayList is passed to the method. This means that any changes made to the elements inside the method persist outside the method. The one exception to this is if you assign the argument to reference a different ArrayList in memory.
Q1: Assuming that the following declaration has been made, which of the following code segments correctly interchanges the value of arr.get(0) and arr.get(5)?
Q2: Consider the following code that is intended to print true if all the elements in arr are even numbers; otherwise it should print false. You may assume that arr has been declared and contains valid integer values.
ArrayList<Integer> numbers = new ArrayList<>();
numbers.add(17);
numbers.add(34);
numbers.add(21);
numbers.add(42);
numbers.add(15);
numbers.add(69);
numbers.add(48);
numbers.add(25);
numbers.add(39);
int x = 3;
for (int k = 1; k < 9; k = k + x)
numbers.set(k, numbers.get(k - 1) + x);