java list主要实现_java – 如何选择正确的List实现?

this CodeReview answer,You seem to use ArrayList for all purposes. There are other List-types in Java that suit certain situations better than an ArrayList. You should have a look at those and try to get a feeling when to use which list. In this particular case i.E. a LinkedList is better.

我也倾向于使用相当大的ArrayList,并且没有看到选择其他列表类型的逻辑.

从ArrayList文档中,

The size,isEmpty,get,set,iterator,and listIterator operations run in constant time. The add operation runs in amortized constant time,that is,adding n elements requires O(n) time. All of the other operations run in linear time (roughly speaking). The constant factor is low compared to that for the LinkedList implementation.

这表明ArrayList通常会胜过LinkedList(this heavily upvoted question支持的断言),尽管LinkedList文档并不能很好地理解性能:

All of the operations perform as could be expected for a doubly-linked list.

CopyOnWriteArrayList对于不变的列表似乎很有用,因为对于正常使用,每次修改的完整快照看起来都非常昂贵.

即使是堆栈文档也不建议使用它:

A more complete and consistent set of LIFO stack operations is provided by the Deque interface and its implementations,which should be used in preference to this class.

由于Vector是同步的而其余的List子类不同步,因此在我看来,Vector将是线程安全环境中的最佳选择.

然而,即使在阅读了文档之后,我仍然认为我不明白TwoThe的答案来自哪里. CopyOnWriteArrayList和Vector每个似乎都有一个专门的用例,Stack似乎不值得使用,而ArrayList似乎优于LinkedList.

我在这里缺少什么,在什么情况下,另一个List实现优于ArrayList?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值