In-depth understanding of the---------of the Java Collection Framework ArrayList collection-----Constructors

Source: Internet
Author: User
Tags int size

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.