Code style and conventions. List<Element> Vs Array Element[]

#1

It seems that throughout the book there is a strong preference in using Lists Vs arrays. For example List instead of int[].

Why is that? Especially when we need to use a 2D array like in problem 19.2 isn’t the code getting unnecessary wordy (e.g: A.get(x).set(y, !A.get(x).get(y)) instead of A[x][y] = !A[x][y])?

Is this just personal style or you recommend using Lists as most interviewers would prefer that?

0 Likes

#2

Hi @strat0sphere,

It is just personal style as List is extendable. Of course it comes with the price that it is tedious to get and set elements.

0 Likes