ArrayList 构造函数有(三种):

  1. public ArrayList(int initialCapacity)
  2. public ArrayList()
  3. public ArrayList(Collection<? extends E> c)
/**
* Constructs an empty list with the specified initial capacity.
*
* @param initialCapacity the initial capacity of the list
* @throws IllegalArgumentException if the specified initial capacity
* is negative
*/
public ArrayList(int initialCapacity) {
if (initialCapacity > 0) {
this.elementData = new Object[initialCapacity];
} else if (initialCapacity == 0) {
this.elementData = EMPTY_ELEMENTDATA;
} else {
throw new IllegalArgumentException("Illegal Capacity: "+
initialCapacity);
}
} /**
* Constructs an empty list with an initial capacity of ten.
*/
public ArrayList() {
this.elementData = DEFAULTCAPACITY_EMPTY_ELEMENTDATA;
} /**
* Constructs a list containing the elements of the specified
* collection, in the order they are returned by the collection's
* iterator.
*
* @param c the collection whose elements are to be placed into this list
* @throws NullPointerException if the specified collection is null
*/
public ArrayList(Collection<? extends E> c) {
elementData = c.toArray();
if ((size = elementData.length) != 0) {
// c.toArray might (incorrectly) not return Object[] (see 6260652)
if (elementData.getClass() != Object[].class)
elementData = Arrays.copyOf(elementData, size, Object[].class);
} else {
// replace with empty array.
this.elementData = EMPTY_ELEMENTDATA;
}
}

ArrayList构造函数有哪些的更多相关文章

  1. 由ArrayList构造函数源码引出的问题

    ArrayList应该用得很多了.最近看了看其源码,发现有很多细节,如果要我们自己来实现,估计会考虑不到.当然,这些细节跟jdk本身一些实现的bug有关,如果不去深挖,定然是不能发现.本文从Array ...

  2. ArrayList构造函数

    //1.摘要: //初始化 System.Collections.ArrayList 类的新实例,该实例为空并且具有默认初始容量. // public ArrayList(); ArrayList a ...

  3. ArrayList

    各种原因,前两年做C语言去了,现在重新做JAVA, 感觉自己基础很不扎实,要好好学习啦, 先从简单的开始~ 以下内容基于jdk1.7.0_79源码: 什么是ArrayList 可以简单的认为是一个动态 ...

  4. Java 集合系列03之 ArrayList详细介绍(源码解析)和使用示例

    概要 上一章,我们学习了Collection的架构.这一章开始,我们对Collection的具体实现类进行讲解:首先,讲解List,而List中ArrayList又最为常用.因此,本章我们讲解Arra ...

  5. Java集合系列:-----------06List的总结(LinkedList,ArrayList等使用场景和性能分析)

    现在,我们再回头看看总结一下List.内容包括:第1部分 List概括第2部分 List使用场景第3部分 LinkedList和ArrayList性能差异分析第4部分 Vector和ArrayList ...

  6. Java 集合系列08之 List总结(LinkedList, ArrayList等使用场景和性能分析)

    概要 前面,我们学完了List的全部内容(ArrayList, LinkedList, Vector, Stack). Java 集合系列03之 ArrayList详细介绍(源码解析)和使用示例 Ja ...

  7. Java 集合系列 03 ArrayList详细介绍(源码解析)和使用示例

    java 集合系列目录: Java 集合系列 01 总体框架 Java 集合系列 02 Collection架构 Java 集合系列 03 ArrayList详细介绍(源码解析)和使用示例 Java ...

  8. ArrayList源码解析

    ArrayList简介 ArrayList定义 1 public class ArrayList<E> extends AbstractList<E> implements L ...

  9. JAVA LinkedList和ArrayList的使用及性能分析

    第1部分 List概括List的框架图List 是一个接口,它继承于Collection的接口.它代表着有序的队列.AbstractList 是一个抽象类,它继承于AbstractCollection ...

随机推荐

  1. Django之CSRF问题

    1.csrf全称:cross site request forgery(跨站请求伪造),举例来讲,一个安全的网站A,一个恶意网站B,当你在A网站进行了登录后,这时候浏览器会保存你的cookie和ses ...

  2. vijos 1164 曹冲养猪

    描述 自从曹冲搞定了大象以后,曹操就开始捉摸让儿子干些事业,于是派他到中原养猪场养猪,可是曹冲满不高兴,于是在工作中马马虎虎,有一次曹操想知道母猪的数量,于是曹冲想狠狠耍曹操一把.举个例子,假如有16 ...

  3. 状态压缩---状态压缩dp第一题

    标签: ACM 题目: Farmer John has purchased a lush new rectangular pasture composed of M by N (1 ≤ M ≤ 12; ...

  4. UVA Live 3713 Astronauts (2-SAT)

    用布尔变量表示状态,把限制条件转化为XνY的形式以后跑2SAT,根据变量取值输出方案. #include<bits/stdc++.h> using namespace std; ; #de ...

  5. kafka 安装以及测试

    1,下载kafka 并进行解压 http://mirrors.cnnic.cn/apache/kafka/0.8.1.1/kafka_2.9.2-0.8.1.1.tgz 2,启动Zookeeper  ...

  6. CPP-网络/通信:WebService

    工具:vc2003 //引入相关头文件,连接动态库,定义全局变量. //***************************************************** #include & ...

  7. C03 程序逻辑

    程序逻辑 运算符 顺序结构 选择结构 循环结构 运算符 赋值运算符:= 比较运算符:>.<.==. >=.<=.!= 逻辑运算符:&&.||.! 顺序结构 在C ...

  8. UVa-213-信息解码

    这题的话,我们只要理解题意,应该就不算很难. 我们可以开一个二维数组,用来存放对应的编码字符,第一个下表是length,第二个下标是value,这样一来,我们在读入数据的时候就进行处理,然后想要使用的 ...

  9. 八:SQL之DQL数据查询语言单表操作

    前言: DQL数据库查询语言是我们在开发中最常使用的SQL,这一章总结了单表操作部分的常用查询方式 主要操作有:查询所有字段.查询指定字段.查询指定记录.带IN的关键字查询,范围查询,陪查询.查询空值 ...

  10. Linux基础学习-使用Squid部署代理缓存服务

    使用Squid部署代理缓存服务 Squid是Linux系统中最为流行的一款高性能代理服务软件,通常作为Web网站的前置缓存服务,能够代替用户向网站服务器请求页面数据并进行缓存.Squid服务配置简单. ...