ArrayList has three methods of construction
ArrayList has three constants
1, private transient object[] elementdata (array); 2, private int size (number of elements)
1, ArrayList (int initialcapacity); Constructs a collection of initial capacity
/** * Serialization */private static final Long Serialversionuid = -6277824875242725854l;/** * Defines an array */private transient object[] E lementdata;/** * Defines the number of elements */private int size;/** * Constructs an array with initial capacity * @param initialcapacity * */public arralist (int initia lcapacity) {super (), if (initialcapacity < 0) {throw new IllegalArgumentException ("Illegal capacity" +initialcapacity );} This.elementdata = new object[initialcapacity];}
2. Construct a set with an initial capacity of 10
/** * Constructs a set with an initial capacity of 10 */public arralist () {this (10);}
3. Construct an entry parameter is a list of collections
/** * Constructs an entry parameter is a collection of list */public arralist (collection<? extends e> c) {//convert array elementdata = C.toarray ();//Set Length size = Elem entdata.length;//judgment is not objectif (elementdata.getclass ()! = Object[].class) {elementdata = arrays.copyof (ElementData, Size,object[].class);}}
In-depth understanding of the---------of the Java Collection Framework ArrayList collection-----Constructors