Vector实现类的底层原理代码解析

Vector实现类的底层原理代码解析,第1张

提示:开发工具IEAD2018,jdk1.8 jdk6AIp参考文档

1.创建Vector实现类对象
//创建Vector实现类
    Vector vector=new Vector();
2.Vector类的底层属性
 protected Object[] elementData;
 protected int elementCount;
 protected int capacityIncrement;
  private static final long serialVersionUID=-2767605614048989439L;
3.Vector类的底层构造器

有参构造器



public Vector(int initialCapacity) {
        this(initialCapacity, 0);
    }

public Vector(int initialCapacity, int capacityIncrement) {
        super();
        if (initialCapacity < 0)
            throw new IllegalArgumentException("Illegal Capacity: "+
                                               initialCapacity);
        this.elementData = new Object[initialCapacity];
        this.capacityIncrement = capacityIncrement;
    }

无参构造器

 public Vector() {
        this(10);
    }

4.vector无参构造器调用过程

//1.创建无参构造器时,
public Vector() {
        this(10);//this(10)调用了有参构造进行默认数值10作为传参数值
    }
//2.有参构造
//initialCapacity=10.无参构造传入的默认参数
public Vector(int initialCapacity) {        this(initialCapacity,capacityIncrement);//capacityIncrement=0
       //this(initialCapacity,capacityIncrement)调用了有参构造并传入个参数 initialCapacity=10,capacityIncrement=0
    }
//3.有参构造
//initialCapacity=10, capacityIncrement=0;
public Vector(int initialCapacity, int capacityIncrement) {
         super();//调用父类构造
        if (initialCapacity < 0)//initialCapacity=10>0
            throw new IllegalArgumentException("Illegal   Capacity: "+
                                          initialCapacity);
                                          
        this.elementData = new Object[initialCapacity];
        
        this.capacityIncrement = capacityIncrement;
        
    }

Vector底层数组的默认容量:10,

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/790826.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-05
下一篇 2022-05-05

发表评论

登录后才能评论

评论列表(0条)

保存