当前位置:网站首页>List介绍
List介绍
2022-06-30 10:10:00 【如风暖阳】

️前言️
本篇文章主要介绍Iterable、Collection、List 的常见方法签名以及含义,三者的关系在下边介绍。
博客主页:【如风暖阳】
精品Java专栏【JavaSE】、【备战蓝桥】、【JavaEE初阶】、【MySQL】、【数据结构】
欢迎点赞收藏留言评论私信必回哟本文由 【如风暖阳】 原创,首发于 CSDN
博主将持续更新学习记录收获,友友们有任何问题可以在评论区留言
Iterable、Collection、List
1.关系图
在集合框架中,三者的关系如下所示,三者都是接口
2.Iterable
Iterable是一个具有迭代功能的泛型接口,表示实现该接口的类是可以逐个元素进行遍历的。
public interface Iterable<T> {
Iterator<T> iterator();
//抽象类中的抽象方法
default void forEach(Consumer<? super T> action) {
Objects.requireNonNull(action);
for (T t : this) {
action.accept(t);
}
}
default Spliterator<T> spliterator() {
return Spliterators.spliteratorUnknownSize(iterator(), 0);
}
}
其内部实现就是通过foreach循环或者调用 iterator() 方法来实现遍历。
3.Collection
Collection是继承于Iterable的泛型接口,用来实现集合的接口。
public interface Collection<E> extends Iterable<E>{
};
常见方法签名:
| 方法 | 作用 |
|---|---|
| add(Object o) | 向集合中添加一个元素 |
| addAll(Collection c) | 向集合中添加集合c的所有元素 |
| clear() | 清除所有元素 |
| contains(Object o) | 判断集合是否包含该元素 |
| containsAll(collection c) | 判断集合是否包含集合c的元素 |
| isEmpty() | 判断集合是否为空 |
| iteration() | 返回iteration对象,用于遍历集合中的所有元素 |
| remove(Object o) | 删除某个指定元素 |
| removeAll(collection c) | 删除集合c中所有元素 |
| retainAll(Collection c) | 仅保留集合c中出现的元素 |
| int size() | 返回集合中元素的个数 |
| Object[] toArray() | 把集合转换为一个数组 |
4.List
List就是一个线性表,即n个具有相同类型元素的有限序列,在该序列上可以执行增删改查以及变量等操作。
注意:
List是个接口,并不能直接用来实例化。
如果要使用,必须去实例化List的实现类。在集合框架中,ArrayList和LinkedList都实现了List接口。
常见方法标签名:
| 方法 | 作用 |
|---|---|
| boolean add(E e) | 尾插 e |
| void add(int index, E element) | 将 e 插入到 index 位置 |
| boolean addAll(Collection<? extends E> c) | 尾插 c 中的元素 |
| E remove(int index) | 删除 index 位置元素 |
| boolean remove(Object o) | 删除遇到的第一个 o |
| E get(int index) | 获取下标 index 位置元素 |
| E set(int index, E element) | 将下标 index 位置元素设置为 element |
| void clear() | 清空 |
| boolean contains(Object o) | 判断 o 是否在线性表中 |
| int indexOf(Object o) | 返回第一个 o 所在下标 |
| int lastIndexOf(Object o) | 返回最后一个 o 的下标 |
| List subList(int fromIndex, int toIndex) | 截取部分 list |
️最后的话️
总结不易,希望uu们不要吝啬你们的哟(^U^)ノ~YO!!如有问题,欢迎评论区批评指正

边栏推荐
- Qt之实现QQ天气预报窗体翻转效果
- 如何解决跨域
- Input a decimal data, convert to 8, using the sequence stack
- Skill combing [email protected] control a dog's running on OLED
- Skill sorting [email protected]+ Alibaba cloud +nbiot+dht11+bh1750+ soil moisture sensor +oled
- CVPR 2022 | Tsinghua & bytek & JD put forward BRT: Bridging Transformer for vision and point cloud 3D target detection
- TypeScript–es5中的类,继承,静态方法
- Memory escape analysis
- [rust daily] several new libraries were released on January 23, 2021
- The performance of arm's new CPU has been improved by 22%, up to 12 cores can be combined, and the GPU is first equipped with hardware optical tracking. Netizen: the gap with apple is growing
猜你喜欢

Mysql database foundation: views and variables

CVPR 2022 | 清华&字节&京东提出BrT:用于视觉和点云3D目标检测的桥接Transformer

无心剑中译狄金森《灵魂择其伴侣》

Retest the cloud native database performance: polardb is still the strongest, while tdsql-c and gaussdb have little change

小程序中读取腾讯文档的表格数据
[email protected]+ Alibaba cloud +nbiot+dht11+bh1750+ soil moisture sensor +oled"/>Skill sorting [email protected]+ Alibaba cloud +nbiot+dht11+bh1750+ soil moisture sensor +oled

Getting started with X86 - take over bare metal control

最新SCI影响因子公布:国产期刊最高破46分!网友:算是把IF玩明白了

Test memory read rate

软件测试工程师面试基础题(应届生和测试小菜必备)最基础的面试题
随机推荐
Gd32 RT thread PWM drive function
Didi open source agile test case management platform!
ArcGIS Pro + PS 矢量化用地规划图
从0使用keil5软件仿真调试GD32F305
LVGL 8.2 Image styling and offset
Skill combing [email protected] intelligent instrument teaching aids based on 51 series single chip microcomputer
Migrate full RT thread to gd32f4xx (detailed)
【Rust日报】2021-01-22 首份Rust月刊杂志邀请大家一起参与
Voir le changement technologique à travers la Légion Huawei (5): Smart Park
运动App如何实现端侧后台保活,让运动记录更完整?
mysql数据库基础:存储过程和函数
pytorch 筆記 torch.nn.BatchNorm1d
GeoffreyHinton:我的五十年深度学习生涯与研究心法
LVGL 8.2图片缩放及旋转
Auto SEG loss: automatic loss function design
超长干货 | Kubernetes命名空间详解
Foster design method
"Hackers and painters" -- why not be stupid
ArcGIS PRO + PS vectorized land use planning map
马斯克推特粉丝过亿了,但他在线失联已一周