import java.util.List;
import java.util.Vector;public class VectorTest {public static void main(String[] args) {List<String> vector = new Vector<>();vector.add("abc");}
}

查看Vector构造方法:

/*** Constructs an empty vector so that its internal data array* has size {@code 10} and its standard capacity increment is* zero.*/public Vector() {this(10);}

查看this(10)

/*** Constructs an empty vector with the specified initial capacity and* with its capacity increment equal to zero.** @param   initialCapacity   the initial capacity of the vector* @throws IllegalArgumentException if the specified initial capacity*         is negative*/public Vector(int initialCapacity) {this(initialCapacity, 0);}

再继续看this(initialCapacity,0)

/*** Constructs an empty vector with the specified initial capacity and* capacity increment.** @param   initialCapacity     the initial capacity of the vector* @param   capacityIncrement   the amount by which the capacity is*                              increased when the vector overflows* @throws IllegalArgumentException if the specified initial capacity*         is negative*/public Vector(int initialCapacity, int capacityIncrement) {super();if (initialCapacity < 0)throw new IllegalArgumentException("Illegal Capacity: "+initialCapacity);this.elementData = new Object[initialCapacity];this.capacityIncrement = capacityIncrement;}

此时initialCapacity为10,capacityIncrement为0,this.elementData为对象数组

/*** The array buffer into which the components of the vector are* stored. The capacity of the vector is the length of this array buffer,* and is at least large enough to contain all the vector's elements.** <p>Any array elements following the last element in the Vector are null.** @serial*/protected Object[] elementData;

所以Vector底层采用的是数组来存放元素的,大部分的public方法都是synchronized的。即同步的。使用不当会造成性能问题。

Vector和ArrayList底层数据结构都是数组。

Vector源码分析相关推荐

  1. Java集合之Vector源码分析

    概述 Vector与ArrayLIst类似, 内部同样维护一个数组, Vector是线程安全的. 方法与ArrayList大体一致, 只是加上 synchronized 关键字, 保证线程安全, 下面 ...

  2. sheng的学习笔记-Vector源码分析

    概述 Vector底层也是数组,跟ArrayList很像(先看下ArrayList,再看Vector会很轻松),ArrayList可参考下文,并且由于效率低,已经被淘汰了,大概瞅瞅得了 sheng的学 ...

  3. C++ STL: 容器vector源码分析

    文章目录 前言 vector的核心接口 vector push_back实现 vector 的 Allocator vector 的 push_back 总结 前言 vector 是我们C++STL中 ...

  4. 【Java源码分析】Vector源码分析

    类的声明 public class Vector<E> extends AbstractList<E> implements List<E>, RandomAcce ...

  5. Java学习集合源码分析

    集合源码分析 1.集合存在的原因 可以用数组来表示集合,那为什么还需要集合? 1)数组的缺陷 ​ 在创建数组时,必须指定长度,一旦指定便不能改变 数组保存必须是同一个类型的数据 数组的增加和删除不方便 ...

  6. c++ vector拷贝构造_JDK源码分析-Vector

    1. 概述 上文「JDK源码分析-ArrayList」主要分析了 ArrayList 的实现原理.本文分析 List 接口的另一个实现类:Vector. Vector 的内部实现与 ArrayList ...

  7. java vector实现的接口_java中List接口的实现类 ArrayList,LinkedList,Vector 的区别 list实现类源码分析...

    java面试中经常被问到list常用的类以及内部实现机制,平时开发也经常用到list集合类,因此做一个源码级别的分析和比较之间的差异. 首先看一下List接口的的继承关系: list接口继承Colle ...

  8. Jaca集合(四)Vector集合底层源码分析

    Vector的基本介绍: (1)Vector类的定义说明:我们进入源码界面进行查看: public class Vector<E>extends AbstractList<E> ...

  9. OpenCV2.4.9源码分析——Support Vector Machines

    引言 本文共分为三个部分,第一个部分介绍SVM的原理,我们全面介绍了5中常用的SVM算法:C-SVC.ν-SVC.单类SVM.ε-SVR和ν-SVR,其中C-SVC和ν-SVC不仅介绍了处理两类分类问 ...

最新文章

  1. 转载:薪资谈判应该避免的7个错误
  2. 农业银行联行号怎么查询_农行信用卡解析丨菜卡怎么提额8W?学会一招就够了!...
  3. 以回调形式使用startActivityForResult方法,并解决Activity被回收的问题
  4. Spring Cloud Alibaba迁移指南(四):零代码兼容 Api-Gateway
  5. 权限分配界面 纯手工 仅用到bootstrap的架构 以及 c标签
  6. Keepalived + Nginx 实现高可用 Web 负载均衡
  7. python 双层for循环_day05-Python运维开发基础(双层循环、pass/break/continue、for循环)...
  8. 年后跳槽必备的 Java 题库,全网最全!
  9. Maven Build Profiles
  10. 武当功夫在现代2 视频
  11. PIC单片机入门教程(一)—— 准备工作
  12. 计算机的优势和劣势_计算机专业毕业生考研还是就业应该怎么选?
  13. 数字信号处理概览与框图
  14. python群发邮箱软件下载_python qq邮件群发
  15. window10添加局域网计算机,win10系统加入局域网连接的设置方案
  16. win7电脑怎么提升开机速度
  17. 网络安全——Burpsuite
  18. 【C语言】动态内存开辟
  19. 大学计算机知识考试题,大学计算机基础理论知识前三章测试题
  20. Qt 程序使用自带 ttf 字体示例

热门文章

  1. Oracle 把触发器说透
  2. SUN JAVA面试笔试题2
  3. 部署xhprof监控php效率(linux版本)
  4. MySQL覆盖索引:直接从索引查询到了数据
  5. python local variable_python学习笔记 - local, global and free variable
  6. python中time模块详解_Python time模块详解
  7. Git 企业中常用分支管理策略
  8. react把表格渲染好ui_《RSUITE》React企业级UI框架实战评测
  9. Windows环境配置Anaconda+cuda+cuDNN+pytorch+jupyter notebook
  10. json与java反射_Java 对象的 Json 化与反 Json 化