Files
Hui-s-notebook/logseq-java/journals/2022_04_19.md
2024-02-02 00:12:49 +08:00

76 lines
1.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
- [[ArrayList]]
- [[迭代器]]
- [[泛型]]
- [[匿名内部类]]
- [[LinkedList]]
- [[Vector]]
- [[HashSet]]
-
-
- 总结
collapsed:: true
- ArrayList
- API
- add()
- set()
- remove()
- contains()
- indexOf()
- isEmpty()
- clear()
- 遍历
- for循环
- 增强for循环
- 迭代器遍历
- 排序
- Collections
- addAll
- sort
- 自然排序
- 要求元素身上必须实现Comparable接口
- 自定义排序
- 自己定义比较器,完成排序规则
- 底层结构
- 迭代器
- 源自于 “迭代器模式”,为了统一集合的遍历方式
- Iterable接口的目的为了让集合具备一定的遍历能力
- Iterator接口的目的为了让集合进行具体的遍历
- 泛型
- 问题:集合在遍历时,向下转型中抛出 类型转换错误的问题
- 泛型:用来规范集合中元素类型
- 格式:<数据类型>
- 泛型接口
- 泛型类
- 泛型擦除
- 匿名内部类
- 定义在某一个方法的内部
- 类没有名字
- 实例化和类的定义一起放置
- 生命周期和方法同步
- LinkedList
- 底层为链表结构
- API与ArrayList一致
- 区别
- 底层结构ArrayList为数组,LinkedList为链表
- ArrayList适用于查询,新增和删除节点时效率低
- LinkedList适用于新增和删除节点,查询效率低
- Vector
- 向量,List中一种非常古老的集合
- API和底层结构与ArrayList一致
- Vector的方法都加了synchronized关键字
- HashSet
- 特点
- 元素存储时可以有序和无序
- 不允许重复元素
- 没有下标
- API
- add
- remove
- size
- 遍历
- 增强for循环
- 迭代器模式
- forEach方法
id:: 625f6ab3-c8c2-4a00-b127-284ce2e9c373
- 排序
- 借助ArrayList的功能排序