重庆网站建设电话三只松鼠口碑营销案例
目录
五、List 接口
5.1 位置
5.2 说明
5.3 特点
5.4 常用方法
五、List 接口
5.1 位置
List 接口位于 java.util
包中
5.2 说明
List 接口是 Collection 接口的子接口
5.3 特点
- List 接口实例中存储的元素是有序的
- List 接口实例允许存储重复的元素
5.4 常用方法
void add(int index,E element) | |
方法名 | add() |
作用 | 在 List 的索引 index 处插入元素 element |
boolean addAll(int index,Collection<? extends E> c) | |
方法名 | addAll() |
作用 | 在 List 的索引 index 处插入集合 c 的所有元素 |
E remove(int index) | |
方法名 | remove() |
作用 | 删除指定索引 index 处的元素 |
注意 | 删除后会返回这个被删除的元素 |
E get(int index) | |
方法名 | get() |
作用 | 返回指定索引 index 处的元素 |
E set(int index,E element) | |
方法名 | set() |
作用 | 将指定索引 index 处的元素替换为 element。并将替换前的元素返回 |
int indexOf(Object o) | |
方法名 | indexOf() |
作用 | 返回对象 o 在 List 中第一次出现的索引 |
int lastIndexOf(Object o) | |
方法名 | lastIndexOf() |
作用 | 返回对象 o 在 List 中最后一次出现的索引 |
List<E> subList(int fromIndex,int toIndex) | |
方法名 | subList() |
作用 | 返回从索引 fromIndex(包括) 到 toIndex(不包括)的所有元素组成的子集合 |
ListIterator<E> listIterator() | |
方法名 | listIterator() |
作用 | 返回列表迭代器对象 |
ListIterator<E> listIterator(int index) | |
方法名 | listIterator() |
参数 | int index:设置列表迭代器的指针位置 |
作用 | 返回从指定位置开始的列表迭代器对象 |
说明 | 其他常用方法,参考 Collection 接口 |