目录:
一:ArrayList的缺陷
二:LinkedList的使用
三:LinkedList的使用
3.1:LinkedList的构造
3.2:LinkedList的其他常用方法
3.3:LinkedList的遍历
四:总结
一:ArrayList的缺陷
?ArrayList底层使用数组来存储元素:由于其底层是一段连续空间,当在ArrayList任意位置插入或者删除元素时,就需要将后序元素整体往前或者往后搬移,时间复杂度为O(n),效率比较低,因此ArrayList不适合做任意位置插入和删除比较多的场景。
因此:java集合中又引入了LinkedList,即链表结构。
二:LinkedList的使用
LinkedList的底层是双向链表结构(不仅知道后面的在哪,还知道前面的在哪)
由于链表没有将元素存储在连续的空间中,元素存储在单独的节点中,然后通过引用将节点连接起来了,因此在在任意位置插入或者删除元素时,不需要搬移元素,效率比较高。



?【说明】
- LinkedList实现了List接口
- LinkedList的底层使用了双向链表
- LinkedList没有实现RandomAccess接口,因此LinkedList不支持随机访问
- LinkedList的任意位置插入和删除元素时效率比较高,时间复杂度为O(1)
三:LinkedList的使用
3.1:LinkedList的构造
方法 | 解释 |
---|
LinkedList() | 无参构造 | public LinkedList(Collection<?extends E>c) | 使用其他集合容器中元素构造List |

?3.2:LinkedList的其他常用方法

?注意: get方法不咋用,因为链式结构要找任意位置的元素不太好找,时间复杂度就成O(N)了。?
3.3:LinkedList的遍历

注意:第一种通过get()方法遍历是效率最慢的,因为时间复杂度是O(N) 。
四:总结
List:
- 接口------>规范了许多方法
- 继承Collection接口
- 从数据结构角度--->线性表
ArrayList:
- 实现了List接口
- 底层使用一个数组(连续空间)存储元素
- 从数据结构角度--->动态类型的顺序表
LinkedList:
- 实现了List接口
- 底层使用双向链表结构存储管理元素
- 从数据结构角度--->双向链表
Vector:
- 实现List接口
- 底层使用数组(连续空间)存储元素
- 从数据结构角度--->动态类型顺序表
- 线程安全
|