数据结构List之Vector
来源:互联网 发布:apache poi 读取excel 编辑:程序博客网 时间:2024/05/16 18:03
Vector和ArrayList都是以Array为底层的链表,它跟ArrayList的不同是它是线程安全的,因此它的速度慢,并且它的容量增长是2倍速度,下面的程序可以证明:
“`
package learnIng;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Vector;
public class VectorTest {
public static void main(String[] args) {
for (int j = 1; j < 100; j++) {
Vector squares = new Vector();
for (int i = 1; i < j; i++)
squares.add(i);
Class c = ((Object) squares).getClass();
Field f;
try {
f = c.getDeclaredField(“elementData”);
f.setAccessible(true);
try {
Object[] o = (Object[]) f.get(squares);
System.out.println(o.length);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
}
}
}
}“`
实验结果:
10
10
10
10
10
10
10
10
10
10
10
20
20
20
20
20
20
20
20
20
20
40
40
40
40
40
40
40
40
40
40
40
40
40
40
40
40
40
40
40
40
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
80
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
因此在大量数据插入的情况下我们选取vector.
- 数据结构List之Vector
- 数据结构之vector&list
- 数据结构之Vector
- 数据结构之vector
- 【一】 数据结构之Vector
- 【数据结构】STL中的vector和list
- vector 与list 之erase
- STL之list/vector/deque
- java数据结构之向量Vector
- java数据结构之List
- 数据结构List之ArrayList
- 数据结构List之LinkedList
- 【二】数据结构之List
- 数据结构之List
- Java 常用数据结构深入分析(Vector、ArrayList、List、Map)
- Java 常用数据结构深入分析(Vector、ArrayList、List、Map)
- C++存储数据结构List、CArray、Vector和Map使用分析
- Java 常用数据结构深入分析(Vector、ArrayList、List、Map)
- 漫谈兼容内核之十二:Windows的APC机制
- 看懂源码之注释规范
- 深入剖析 redis 事件驱动
- 3.3 Git 分支 - 分支管理
- java bean 与 表单自动匹配
- 数据结构List之Vector
- 【Android应用开发】Android View 组件
- android处理运行时的变更(较大数据的保存)
- 动态获取屏幕宽高
- 3.4 Git 分支 - 分支开发工作流
- ThinkPHP5.0学习笔记
- key permission
- 好用的插件分享
- 菜单点击/关注/取消关注