更新时间:2023-02-26 22:14:08
几乎总是 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
实现的信息 这里.
You can read about the List
implementations here.
您可能从 ArrayList
开始,但很快就会发现另一个实现是更合适的选择.
You may start with an ArrayList
, but soon after discover that another implementation is the more appropriate choice.