什么是ArrayList和Vector的区别? [英] What are the differences between ArrayList and Vector?

查看:135
本文介绍了什么是ArrayList和Vector的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是这两个数据结构和你应该使用每个它们之间的区别是什么?

What are the differences between these two data structures and where should you use each of them?

推荐答案

的差异


  • 载体是同步的,的ArrayList
    不是。

  • 数据增长的方法

使用的ArrayList如果没有使用载体的具体要求。

Use ArrayLists if there is no specific requirement to use Vectors.

同步

如果多个线程同时访问一个ArrayList同时那么我们就必须同步外部code的这修改了该列表无论结构还是简单的修改元素块。结构改性装置加成或从列表元素(多个)的删除。设置的现有元素的值是不是结构修改

If multiple threads access an ArrayList concurrently then we must externally synchronize the block of code which modifies the list either structurally or simply modifies an element. Structural modification means addition or deletion of element(s) from the list. Setting the value of an existing element is not a structural modification.

Col​​lections.synchronizedList通常在创建列表时使用的,以避免对列表中的任何意外的不同步访问

Collections.synchronizedList is normally used at the time of creation of the list to avoid any accidental unsynchronized access to the list.

<一个href=\"http://geekexplains.blogspot.com/2008/05/difference-between-vector-and-arraylist.html\">Reference

数据增长

在内部,无论是ArrayList和Vector守住使用数组的内容。当一个元素插入ArrayList或载体,对象将需要的,如果它运行的空间来扩大其内部数组。 的矢量默认翻番数组的大小,而ArrayList的50%增加了数组的大小。

Internally, both the ArrayList and Vector hold onto their contents using an Array. When an element is inserted into an ArrayList or a Vector, the object will need to expand its internal array if it runs out of room. A Vector defaults to doubling the size of its array, while the ArrayList increases its array size by 50 percent.

参考

这篇关于什么是ArrayList和Vector的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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