当前位置:网站首页>arraylist之与linkedlist
arraylist之与linkedlist
2022-08-11 05:13:00 【SunForYou】
1 arraylist实现基于数组 linkedlist实现基于链表
2 随机访问get arraylist可以根据下标直接get linkedlist get 首先传入一个index,判断index是否大于linkedlist size的一半,如果不大于从前端遍历,如果大于从后端遍历,找到对应index元素,对于随机的get arraylist由于linkedlist
3 add和remove
arraylist尾部添加数据直接在尾部插入,在arraylist中间插入数据,插入位置之后的数据需要往后移动一位,插入数据时涉及到扩容机制,每次扩容后数组长度是扩容前的1.5倍,最大容量是Integer.value-8。
arraylist remove一个数据,remove位置之后的数据需要往前移动一位。
linkedlist尾部添加数据直接在原尾部元素的next指向新加的元素,在linkedlist中间add一个元素,需要把插入位置前后元素的next,pre重新指向。
linkedlist remove一个元素需要把remove位置前后的元素的next,pre重新指向
对于add和remove linkedlist由于arraylist.
边栏推荐
- 让你代码越来越高大上的技巧——代码规范,你得知道
- 玩转mysql之查看mysql版本号
- HAVE FUN | “SOFA 星球”飞船计划、源码解析活动最新进展
- Switch and Router Technology-33-Static NAT
- Mysql introductory exercise
- 【无2022上海市安全员A证考试题库及模拟考试
- C语言题解:谁是凶手!
- BGP Comprehensive Experiment
- [FPGA tutorial case 49] Control case 1 - FPGA-based PID controller verilog implementation
- DS220702-0707作业
猜你喜欢
随机推荐
BGP综合实验
Switches and routers technology - 24 - configure OSPF single area
Delphi7学习记录-demo实例
MySQL索引
4 Module 3: Literature Reading and Research Methods
Win10远程连接(实现多用户同时连接)
MySQL必知必会(初级篇)
LeetCode刷题Top100之两数之和
[ARM] rk3399 mounts nfs error
Switch and Router Technology - 22/23 - OSPF Dynamic Routing Protocol/Link State Synchronization Process
【嵌入式开源库】cJSON的使用,高效精简的json解析库
How to read a paper
Trilium使用总结
C语言:实用调试技巧
2022 building welder (building a special type of work) examination questions and simulation test
IDEA中配置checkstyle
guava RateLimiter均匀限流
Network Skill Tree
【嵌入式开源库】MultiTimer 的使用,一款可无限扩展的软件定时器
redis分布式锁