当前位置:网站首页>深入理解ArrayList和LinkedList!
深入理解ArrayList和LinkedList!
2022-07-18 18:03:00 【一个小白QAQ】
深入理解ArrayList和LinkedList
ArrayList和LinkedList都是实现了List接口
1 ArrayList底层是由数组来实现的
优点:基于动态的数组实现,有确定的下标,读和改更加容易,存放元素可以重复,也可以为null,有序
缺点:不适合对元素进行频繁的插入和删除,插入和删除都需要做大量的元素移动
特点:集合中默认创建为一个大小为10的数组,执行add方法时,会首先执行ensureCapacity()方法,当元素数量正好为数组大小时,会创建一个新的数组,数组大小为原来数组的1.5倍,然后再将所有元素存放进扩充后的数组
2 LinkList底层则是由双向链表来实现
优点:由于是由双链表实现的,其头节点和尾节点很容易的进行修改,插入和删除只需修改前一元素的尾节点和后一元素的头节点即可,增删不需要移动原有的元素
缺点:查询和修改需要遍历整个链表来查找元素,不利于查找和修改
特点:执行add方法时,将要插入的位置前一个元素的尾节点指向要插入元素的头节点,要加入元素的头节点指向前一个元素的尾节点,然后要插入元素的尾结点指向后一个元素的头节点,后一个元素的头节点指向要插入元素的尾节点(删除操作类似)
3、程序测试
当我们创建一个新的ArrayList时,往里面一直添加元素,第一个元素添加后,显示list的size为1,当我们debug进入add方法查看,elementData已经是一个大小为10的数组,说明默认创建就是为一个大小为十的数组
当我们添加到第十一个元素时候,再次debug进入add方法,查看此时的elementData数组的大小已经扩充到了15,说明当元素的数量大于当前已经创建的elementData数组的大小时,会对elementData进行扩充,每次扩充1.5倍
边栏推荐
- The virus in the USB flash disk turned the file into Exe file
- FileInputStream与BufferedInputStream的区别
- Shell script case
- Six certificates related to data governance are most worthy of recommendation. Remember to collect them!
- How to realize online 3D model display
- What if SolidWorks document cannot be opened normally?
- List集合
- YOLOV3
- List,Set,Map,Queue,Deque,Stack的遍历方式
- 3D Web visualization engine hoops communicator 2022 SP1 update highlights: new support for 2 formats, selective loading of CAD views
猜你喜欢
Missing the size again? See how SolidWorks MBD can help you solve it!
牛客 SQL51 查找字符串 10,A,B 中逗号,出现的次数cnt
CISP-PTE和CISP-PTS之间的区别和联系
Understand the model reduction operation in hoops exchange in three aspects
听说PDM不够用?SOLIDWORKS Manage了解一下
Inventory information security CISP family popular certification
使用IPsec保证IP数据报文在网络上安全传输
PWM output mode
牛客sql题第七题——group by和having
收藏!Solidworks设备布局工具:SOLIDWORKS Asset Publisher
随机推荐
Construction of training operation software for chemical virtual simulation laboratory
What are the differences and connections between cise and CISO? How to choose?
1. Use of pyqt -- inherit window and window display
路由协议BGP的概述学习——入门必看
What types of 3D virtual digital human?
CISE、CISO、有什么区别和联系?怎么选?
What are the directions of CISP?
Notes before CDMP certification examination
CISP-PTE和CISAW认证的区别有哪些?
3D software development tool hoops full product development introduction | hoops exchange, hoops communicator
Map接口下的实现类
Batch convert xlsx files to CSV files
阐述一些关于交换机的考试难点知识
文件解析 (JSON解析)
牛客 SQL51 查找字符串 10,A,B 中逗号,出现的次数cnt
The virus in the USB flash disk turned the file into Exe file
Visual digital twin smart Park simulation display construction scheme
2022 hoops product introduction | hoops exchange, hoops visualize, hoops communicator, hoops publish
CISA证书含金量大吗?
卸载yum安装的zabbix软件