Arrays are more efficient, both in terms of processing time and memory footprint. This particularly applies if you are operating on primitive types, such as int
or long
, since List
requires all elements to be wrapped in an Object
(such as Integer
or Long
). While the autoboxing features introduced by Java 5 reduces the amount of code you need for such wrapping and unwrapping, it does not remove the performance issues, as wrapper objects are still being created.
However, most applications probably do not have any performance bottlenecks related to these issues, so in most cases, List
and other collections should do fine. In these cases, the ease of programming outweighs the increase in memory or CPU usage, and List
is the right choice.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…