更新时间:2023-02-26 22:18:40
几乎总是 List
优于 ArrayList
因为,例如,List
> 可以翻译成LinkedList
不影响代码库的其余部分.
Almost always List
is preferred over ArrayList
because, for instance, List
can be translated into a LinkedList
without affecting the rest of the codebase.
如果使用ArrayList
而不是List
,则很难将ArrayList
实现更改为LinkedList
实现因为在代码库中使用了 ArrayList
特定方法,这些方法也需要重构.
If one used ArrayList
instead of List
, it's hard to change the ArrayList
implementation into a LinkedList
one because ArrayList
specific methods have been used in the codebase that would also require restructuring.
您可以阅读List
实现这里.
您可以从 ArrayList
开始,但很快就会发现另一个实现是更合适的选择.
You may start with an ArrayList
, but soon after discover that another implementation is the more appropriate choice.