如果线程安全不是一个问题,ArrayList与Vectors在Java中 [英] ArrayList vs. Vectors in Java if thread safety isn't a concern

查看:137
本文介绍了如果线程安全不是一个问题,ArrayList与Vectors在Java中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Vector ArrayList 的性能有很大的区别吗?在线程安全不是问题的任何时候都使用ArrayLists是好的做法吗?

Is there really that much of a difference between the performance of Vector and ArrayList? Is it good practice to use ArrayLists at all times when thread safety isn't an issue?

推荐答案

- 收集API天数,并已经改装,因为它是它的一部分。从我读过的内容,它不被弃用的原因是因为核心API依赖于它。

Vector originates back from the pre-Collections API days, and have been retrofitted since to be a part of it. From what I've read, the reason it is not deprecated is because the core API depends on it.

ArrayList是从零开始编写的,作为Collections API的一部分,因此应该使用,除非你需要支持低至1.2的Java版本。

ArrayList was written from scratch as a part of the Collections API and as such should be used unless you need to support Java versions down to 1.2.

如果你需要一个线程安全的ArrayList,你可以使用静态工厂方法 Collections.synchronizedList(new ArrayList< type>); 来生成您的列表。

If you need a thread-safe ArrayList, you can use the static factory method Collections.synchronizedList(new ArrayList<type>); to generate your list.

这篇关于如果线程安全不是一个问题,ArrayList与Vectors在Java中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆