ArrayList比较简单,主要是通过数组来实现的

需要注意的是其初始容量是10

    /**
* Default initial capacity.
*/
private static final int DEFAULT_CAPACITY = 10;

需要注意增长方法grow()

/**
* Increases the capacity to ensure that it can hold at least the
* number of elements specified by the minimum capacity argument.
*
* @param minCapacity the desired minimum capacity
*/
private void grow(int minCapacity) {
// overflow-conscious code
int oldCapacity = elementData.length;
int newCapacity = oldCapacity + (oldCapacity >> 1);
if (newCapacity - minCapacity < 0)
newCapacity = minCapacity;
if (newCapacity - MAX_ARRAY_SIZE > 0)
newCapacity = hugeCapacity(minCapacity);
// minCapacity is usually close to size, so this is a win:
elementData = Arrays.copyOf(elementData, newCapacity);
}

只要size > 数组的长度,就会触发grow,其中增长比例是原来的容量的一半

        int oldCapacity = elementData.length;
int newCapacity = oldCapacity + (oldCapacity >> 1);

然后把原来数组的内容拷贝到新的数组

========================================================================分割线========================================================

ArrayList和LinkedList的区别

ArrayList是通过数组来实现的,读取性能很高,随机访问时间复杂度为O(1),适用于读大于写的场景

LinkedList是是通过双向队列来实现的,更新效率更高,写只需要修改前后两个节点的相关引用,但是读取效率比较低,需要最多遍历一半长度的队列,适用与写大于读的场景

.ArrayList是如何实现的,ArrayList和LinkedList的区别?ArrayList如何实现扩容?的更多相关文章

  1. Java进阶(十七)ArrayList与LinkedList的区别

    ArrayList与LinkedList的区别 ArrayList ArrayList其实是包装了一个数组 Object[],当实例化一个ArrayList时,一个数组也被实例化,当向ArrayLis ...

  2. 源码分析二(ArrayList与LinkedList的区别)

    一:首先看一下ArrayList类的结构体系: public class ArrayList<E> extends AbstractList<E> implements Lis ...

  3. java集合框架之ArrayList与LinkedList的区别

    参考http://how2j.cn/k/collection/collection-arraylist-vs-linkedlist/690.html#nowhere ArrayList和LinkedL ...

  4. Array 和 ArrayList 、 List 以及 LinkedList 的区别

    下面列出了Array(数组)和ArrayList(集合)的不同点: Array可以包含基本类型和对象类型,ArrayList只能包含对象类型. Array大小是固定的,ArrayList的大小是动态变 ...

  5. Java自学-集合框架 ArrayList和LinkedList的区别

    ArrayList和LinkedList的区别 步骤 1 : ArrayList和LinkedList的区别 ArrayList ,插入,删除数据慢 LinkedList, 插入,删除数据快 Arra ...

  6. LintCode Reverse LinkedList (ArrayList 和 LinkedList 的区别)

    1. ArrayList 和 LinkedList 的区别 http://pengcqu.iteye.com/blog/502676 2. How to reverse LinkedList http ...

  7. 你真的说的清楚ArrayList和LinkedList的区别吗

    参见java面试的程序员,十有八九会遇到ArrayList和LinkedList的区别?相信很多看到这个问题的人,都能回答个一二.但是,真正搞清楚的话,还得花费一番功夫. 下面我从4个方面来谈谈这个问 ...

  8. Java基础-ArrayList和LinkedList的区别

    大致区别:  1.ArrayList是实现了基于动态数组的数据结构,LinkedList基于链表的数据结构. 2.对于随机访问get和set,ArrayList觉得优于LinkedList,因为Lin ...

  9. ArrayList、Vector、LinkedList的区别及其优缺点? (转载)

    原文链接:http://blog.csdn.net/wangzff/article/details/7296648 ArrayList,LinkedList,Vestor这三个类都实现了java.ut ...

随机推荐

  1. 编译原理_P1003

    1. 语法分析 1.1 上下文无关文法的定义 ----  正规式能定义一下简单的语言,能表示给定结构的固定次数的重复或者没有指定次数的重复 例如:a(ba)5,a(ba)* ---- 正规式不能用于描 ...

  2. NOIP 2004 T3 合唱队形(DP、最长上升/下降子序列)

    链接:https://ac.nowcoder.com/acm/contest/1082/C来源:牛客网 题目描述 N位同学站成一排,音乐老师要请其中的(N-K)位同学出列,使得剩下的K位同学排成合唱队 ...

  3. 基础篇四:Ngnix安装

    然后直接 yum  install nginx 安装nginx

  4. day39-进程-队列

    #队列Queue:进程之间数据是隔离的,不共享的,但是通过multiprocessing的Queue可以实现进程之间的通信. #1.先进先出:把1 2 3放到队列里,按1 2 3的顺序拿出来. fro ...

  5. vue2.0学习之组件间通信

    /* child.vue*/ 子组件 <template> <div> /*必须要用div包裹起来,然后在里面写需要的组件内容,这里面和平常写的html是一样的*/ <d ...

  6. 疯狂收集个人信息的谷歌,为何不像Facebook那样让人毛骨悚然?

    自从Facebook信息泄露丑闻事件发生后,互联网上的个人隐私及安全成为大众的"心病".而大众最讨厌的,是互联网企业收集自己的信息,因此都在积极讨伐这种行为.但他们却忘了,收集用户 ...

  7. Bringing up interface eth0: Device eth0 does not seem to be present, delaying initialization.FAILED

    1.service network stop 2./etc/sysconfig/network-scripts目录下,删除想要删除的网卡配置,我要删除eth1,所以rm -rf ifcfg-eth1, ...

  8. HDU-1251-统计难题(Trie树)(BST)(AVL)

    字典树解法(Trie树) Accepted 1251 156MS 45400K 949 B C++ #include"iostream" #include"cstdlib ...

  9. Linux Ubuntu 查看IP

    一.第一种方式:ifconfig -a 1.打开命令终端:Crtl + Alt + T 2.执行命令:ifconfig -a 如果你没有安装net-tools工具,则出现如下显示: (没有找到'ifc ...

  10. Win32 计时器

    计时器精确吗? 计时器并不精确.有两个原因: 原因一:Windows计时器是硬件和ROM BIOS架构下之计时器一种相对简单的扩充.回到Windows以前的MS-DOS程序写作环境下,应用程式能够通过 ...