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

提示:开发工具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实现类的底层原理代码解析_第1张图片

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

你可能感兴趣的:(集合,eclipse,java)