Java: Why Lists instead of arrays?

#1

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.

0 Likes

#2

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.

0 Likes