Vector vs. ArrayList哪个更好? [重复]

时间:2022-05-19 17:03:58

Possible Duplicate:
Why is Java Vector class considered obsolete or deprecated?

可能重复:为什么Java Vector类被认为已过时或已弃用?

Which type is better to use and how to choice right type (memory usage, execution...)?

哪种类型更好用,如何选择正确的类型(内存使用,执行...)?

2 个解决方案

#1


28  

As per this question Vector is considered "obsolete", use ArrayList instead.

根据这个问题,Vector被认为是“过时的”,而是使用ArrayList。

#2


50  

You should normally use ArrayList - it offers better performance.

您通常应该使用ArrayList - 它提供更好的性能。

Vector has just one "advantage" - it is synchronised for concurrent modification. But it turns out in practice that this feature isn't very useful because Vector synchronises at the level of each individual operation. If you are writing concurrent code, you typically need to lock at a much higher level of granularity than an individual collection class.

Vector只有一个“优势” - 它可以同步进行并发修改。但事实证明,此功能并不是非常有用,因为Vector会在每个单独的操作级别进行同步。如果要编写并发代码,则通常需要锁定比单个集合类更高的粒度级别。

As a result, Vector is often considered deprecated nowadays.

因此,Vector现在通常被认为已被弃用。

#1


28  

As per this question Vector is considered "obsolete", use ArrayList instead.

根据这个问题,Vector被认为是“过时的”,而是使用ArrayList。

#2


50  

You should normally use ArrayList - it offers better performance.

您通常应该使用ArrayList - 它提供更好的性能。

Vector has just one "advantage" - it is synchronised for concurrent modification. But it turns out in practice that this feature isn't very useful because Vector synchronises at the level of each individual operation. If you are writing concurrent code, you typically need to lock at a much higher level of granularity than an individual collection class.

Vector只有一个“优势” - 它可以同步进行并发修改。但事实证明,此功能并不是非常有用,因为Vector会在每个单独的操作级别进行同步。如果要编写并发代码,则通常需要锁定比单个集合类更高的粒度级别。

As a result, Vector is often considered deprecated nowadays.

因此,Vector现在通常被认为已被弃用。