当前位置:网站首页>线性存储
线性存储
2022-08-05 22:51:00 【Qwe7】
线性存储
ArrayList 类
【数组序列】实现了 List 接口,内部使用 Object 数组存储:
- 可以高效地按索引进行元素修改和查询。
- 添加元素时动态扩容:当容量满后,ArrayList 类会新建一个 1.5 倍容量的新数组,然后将当前数组数据全部复制过去。
ArrayList 构造方法
List<Integer> list = new ArrayList<>(); // 默认初始容量为 10
List<Integer> list = new ArrayList<>(100); // 自定义初始容量
List<Integer> list = new ArrayList<>(queue); // 构造时直接复制其他容器元素(可以是任何 Collection 类)
List list = new ArrayList(); // 未指定元素类型则为 Object 类Copy to clipboardErrorCopiedLinkedList 类
【链表序列】实现了 List 和 Deque 接口。内部使用双向链表存储:
- 可以高效地进行元素插入和删除。
- 容量无限。
LinkedList 构造方法
List<String> list = new LinkedList<>(); // 创建空对象
List<String> list = new LinkedList<>(queue); // 复制其他容器元素Copy to clipboardErrorCopiedArrayDeque 类
【数组双端队列】实现了 Deque 接口。内部使用 Object 数组存储(不允许存储 null 值):
- 可以高效进行元素查找和尾部插入取出,是用作队列、双端队列、栈甚至递归树的绝佳选择。
- 添加元素时动态扩容:当容量满后,ArrayDeque 类会新建一个 1.5 倍容量的新数组,然后将当前数组数据全部复制过去。
ArrayDeque 构造方法
ArrayDeque<String> queue = new ArrayDeque<>(); // 创建空对象
ArrayDeque<String> queue = new ArrayDeque<>(list); // 复制其他容器元素Copy to clipboardErrorCopiedPriorityQueue 类
【无界优先级队列】实现了 Queue 接口。内部使用 Object 数组存储(不允许存储 null 值):
- PriorityQueue 类内会自动对元素进行排序,是作为堆的绝佳选择。但实际在数组中并不是有序存储,而只保证队首元素是最小值:每次弹出队首元素后会自动查找剩余队列中的最小元素放到队首。
- 添加元素时动态扩容:当容量满后,PriorityQueue 类会新建一个 1.5 倍容量的新数组,然后将当前数组数据全部复制过去。
PriorityQueue 构造方法
开发者在构造队列时可通过重写 compare 方法自定义排序规则。如果存储未重写 compareTo 方法的自定义对象,则必须重写 compare 方法。
// 默认排序方法
PriorityQueue<Integer> queue = new PriorityQueue<Integer>();
// 自定义排序方法(Lambda 表达式)
PriorityQueue<Student> queue = new PriorityQueue<Student>((s1, s2) -> {
if(s1.getScore() == s2.getScore()){
return s1.getName().compareTo(s2.getName());
}
return s1.getScore() - s2.getScore();
});边栏推荐
- Where can I get a secure low-commission account channel
- Login and register (unpackaged) flask
- 快速排序(Quick Sort)
- How the Internet of Things is Driving Agriculture
- OCCT示例学习笔记3--Modeling项目
- APS Solutions for Printing Industry
- Meet Alluxio, the "middleman" in MRS
- 游戏思考20:前缀树用途、实现及优化
- IDEA中如何使用debug调试项目 一步一步详细教程
- MUI底部菜单栏 uniapp 底部菜单栏
猜你喜欢
随机推荐
MySQL数据库约束与表的设计
使用MQ的时候,怎么确保消息100%不丢失?
Basic use of CardView, DrawerLayout sliding menu, Fragment
[Home Assistant]esp32 Bafa cloud access ha
为什么五千块天价加急费都无法保证交期?
Redies (4) Optimization of session sharing
如何优雅的消除系统重复代码
js监听退出全屏事件
leetcode:287.寻找重复数
C#Dictionary不能添加重复键的解决方法
Day11:二叉树---->满~、完全~、堆
快速排序(Quick Sort)
Nanoprobes丨GoldiBlot 用于 His-tag 检测方案
有关CRT密码反编译问题
【TypeScript】什么是字面量类型、类型推断、类型拓宽和类型缩小?
[Flask] Deploy flask using gevent
How to use debug to debug projects in IDEA step-by-step detailed tutorial
[GKCTF 2021]easycms
AWTK开发编译环境踩坑记录2(VS Code检测到#include 错误)
归并排序(Merge Sort)




![[GKCTF 2021]easycms](/img/8d/1d83f81f2130a44e98f2cf3dfcf71c.png)




