ArrayList、LinkedList区别(jdk8)
/**
* jdk8
* ArrayList:底层动态数组实现(未初始化指定数组长度)
* add():添加元素时,才初始化数组长度为10。容量不够时,动态扩容策略为: 原容量 + 原容量*0.5
* get():根据数组索引直接查询数组
* remove():根据索引查询数组,然后将其他数据进行前移,最后将最后的那个索引对应值置为Null,等待GC回收
*==================================================================================
* LinkedList: 底层双向链表实现
* Node(Node<E> prev, E element, Node<E> next) {
* this.item = element;
* this.next = next;
* this.prev = prev;
* }
*
* final Node<E> newNode = new Node<>(l, e, null);
* last = newNode;
* if (l == null)
first = newNode;
* else
* l.next = newNode;
*
* =================================================================
* add()方法添加过程:new Node(),将element存放在newNode中,newNode.prev 指向last节点
* newNode.next 指向null
* 判断last节点是否为空,若为null,则 first = last = newNode;
* 否则last.next执行newNode
*
* newNode.prev 绑定 last,last.next 绑定 newNode,实现双向绑定(双向链表)
*
*
* ================================================================
* add(index,element)方法添加过程:
* 判断index是否等于当前集合大小,若等于则直接类似add()方法添加
* 若不等于,则:
* 1、根据index查询将要插入位置的节点 Node node(index)
* 2、linkBefore(element, node(index));
* Node<E> succ = node(index);
*
* Node pred = succ.prev
*
* ******将newNode绑定在succ和succ.prev之间*************
* 将newNode.next = succ
* 将newNode.prev = pred;
*
* ---------将succ.prev,pred.next重新指向newNode,实现双向绑定------
* 将succ.prev = newNode
* 将pred.next = newNode
*
*
* public void add(int index, E element) {
* if (index == size)
* linkLast(element);
* else
* linkBefore(element, node(index));
* }
*
*
* // 找到新插入位置的节点的next或prev
* Node<E> node(int index) {
* // assert isElementIndex(index);
*
* if (index < (size >> 1)) {
* Node<E> x = first;
* for (int i = 0; i < index; i++)
* x = x.next;
* return x;
* } else {
* Node<E> x = last;
* for (int i = size - 1; i > index; i--)
* x = x.prev;
* return x;
* }
* }
*
*
* void linkBefore(E e, Node<E> succ) {
* // assert succ != null;
* final Node<E> pred = succ.prev;
* final Node<E> newNode = new Node<>(pred, e, succ);
* succ.prev = newNode;
* if (pred == null)
* first = newNode;
* else
* pred.next = newNode;
* size++;
* modCount++;
* }
*
* 综上:
* ArrayList:动态数组实现;对于指定位置的添加和删除操作之后,都会有移动元素操作。导致效率低下,而查询则根据索引直接定位,效率高
*
* LinkedList:双向链表实现,对于指定位置的添加和删除操作之后,只需要修改其位置节点执向即可,效率高。而查询则根据节点引用层层调用,效率低下
*
*/
ArrayList、LinkedList区别(jdk8)的更多相关文章
- Java ArrayList和Vector、LinkedList与ArrayList、数组(Array)和列表集合(ArrayList)的区别
ArrayList和Vector的区别ArrayList与Vector主要从二方面来说. 一.同步性: Vector是线程安全的,也就是说是同步的,而ArrayList是线程序不安全的,不是同步 ...
- LinkedList和ArrayList的区别/何时使用LinkedList和ArrayList
1.ArrayList是实现了基于动态数组的数据结构,LinkedList基于链表的数据结构. 2.对于随机访问get和set,ArrayList觉得优于LinkedList,因为LinkedList ...
- 简谈ArrayList和LinkedList区别
对于ArrayList和LinkedList,他们都实现了List接口,他们的区别大致为: ArrayList LinkedList (1)底层是数组,可以以O(1)的时间复杂度对元素进行随机访问 以 ...
- String[]和ArrayList和LinkedList区别
String[]和ArrayList和LinkedList区别 参考文档如下: http://www.blogjava.net/flysky19/articles/92775.html http:// ...
- LinkedList和ArrayList的区别
LinkedeList和ArrayList都实现了List接口,但是它们的工作原理却不一样.它们之间最主要的区别在于ArrayList是可改变大小的数组,而LinkedList是双向链接串列(doub ...
- Hashtable,HashMap,TreeMap有什么区别?Vector,ArrayList,LinkedList有什么区别?int和Integer有什么区别?
接着上篇继续更新. /*请尊重作者劳动成果,转载请标明原文链接:*/ /*https://www.cnblogs.com/jpcflyer/p/10759447.html* / 题目一:Hashtab ...
- List的三个子类ArrayList,LinkedList,Vector区别
一:List的三个子类的特点 ArrayList: 底层数据结构是数组,查询快,增删慢. 线程不安全,效率高.Vector: 底层数据结构是数组,查询快,增删慢. 线程安全,效率低.Vector相对A ...
- Android LinkedList和ArrayList的区别
LinkedeList和ArrayList都实现了List接口,但是它们的工作原理却不一样.它们之间最主要的区别在于ArrayList是可改变大小的数组,而LinkedList是双向链接串列(doub ...
- 一、基础篇--1.2Java集合-Arraylist 与 LinkedList 区别
Arraylist 与 LinkedList 区别 结构上的区别 ArrayList底层实现基于动态数组,LinkedList底层实现基于双向链表. 性能上区别 ArrayList查询快,增删慢 ...
随机推荐
- 《python可以这样学》第一章
一.Python基础 查看Python版本 Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AM ...
- 移动端键盘顶起遮挡输入框&offsetTop值不准问题
先上图 通常在开发中我们会遇到这样输入框被遮挡的问题,那么该怎么解决呢? 方案一(css): 首先,把置底元素设置成,在页面的底部而非屏幕的底部 .page .bottom { position ...
- TFT液晶显示屏之绘图板应用
应用范例: 使用 TOPWAY Smart LCD (HMT043FC-1C) 绘图板应用 第一步建立工程 ① 开TOPWAY TML Graphic Editor 2017 V1.04软件, 点击菜 ...
- djinn:1 Vulnhub Walkthrough
靶机下载链接: https://download.vulnhub.com/djinn/djinn.ova 主机端口扫描: FTP发现一些文件提示 1337端口是一个游戏,去看下 哈哈有点难,暂时放弃, ...
- 何时使用异步或同步AJAX
通常最好使用异步调用 通过优锐课核心java学习笔记中,我们可以看到,码了很多专业的相关知识, 分享给大家参考学习. AJAX代表异步JavaScript和XML,是一项允许异步更新网页的技术,这意味 ...
- 安装Linux系统时LSI RAID卡的驱动挂载
转载原文地址:https://www.jianshu.com/p/64415712401e 当使用较新的SAS卡来安装Linux系统时,经常会遇到在系统安装界面读不到RAID的情况,这时就需要考虑Li ...
- c#画图之雷达图
public JsonResult DrawRadar() { List<Color> colors = new List<Color>() { Color.FromArgb( ...
- scanf 与fgets
scanf: 1.以输入字符串也可以输入数字 . 2.遇到空格就停止.3.会有segmentation fault. fgets: 1.只能输入字符串.2.回车才会停止.3.不会有segmenntat ...
- windows服务踩的坑
最近写了一个windows服务 有一些bug最后终于解决了还是写点经验把. 第一点.版本问题,因为是小白,第一次写windows服务,选择的是.net4.6.1的目标框架,因为我的电脑是windows ...
- css3基础-文本与字体+转换+过渡+动画+案例
Css3文本与字体 文本阴影 h1 { text-shadow: 5px 5px 5px red; } word-break换行: h1:nth-child(1) { word-break: no ...