List集合
2025年9月28日小于 1 分钟
List集合
- 属于 Collection集合 的子接口
List集合特有方法
注意
List集合继承于Collection集合,因此也继承了 Collection集合的常用方法 ,这里不在赘述
| 方法名称 | 说明 |
|---|---|
void add(int index, E element) | 在指定索引处添加元素 |
E remove(int index) | 删除指定索引处的元素,并返回 |
E set(int index, E element) | 修改指定索引的元素,并返回 |
E get(int index) | 获取指定索引处的元素 |
List集合支持的遍历方式
- for循环遍历(因为支持索引)
- 迭代器遍历
- 增强for循环遍历
- Lambda表达式遍历