Java: Why Lists instead of arrays?


I don’t understand why all the examples in the chapter named Arrays are implemented using lists?
Although I understand that ArrayList is backed by an array, but it doesn’t mean it is an array. ArrayList is a List!

Why there is not 1 example using arrays? do you think this
A.set(i, A.get(i)+1)
is clearer/more beautiful/faster than
A[i]++ ?

The book is very good and I really like it.



This thread certainly is old.: ) But here’s one other downside of using lists, and that is the “hidden complexity” of list.get(i). Unless it’s assumed that ArrayLists will always be used, a LinkedList's get(i) method can affect an algorithm’s time complexity.