List接口之ArrayList

1.List是Collection的子接口
2.List接口的主要实现类ArrayList
3.常用方法
void add(int index, Object ele):在指定的索引位置添加元素
boolean addAll(int index, Collection eles):在指定的索引位置添加一个集合
Object get(int index):获取指定索引位置的元素
int indexOf(Object obj):返回obj在集合中首次出现的位置,如果没有找到索 引,则返回-1
int lastIndexOf(Object obj):返回obj在集合中最后一次出现的位置,如果没有找到索引,则返回-1
Object remove(int index):删除指定索引的元素
Object set(int index, Object ele)设置(替换)指定索引位置的元素
List subList(int fromIndex, int toIndex)
(该方法返回的是父list的一个视图,从fromIndex(包含),到toIndex(不包含)。fromIndex=toIndex 表示子list为空)
4.特有名词:
hashcode:代表对象的地址说的是对象在hash表中的位置,物理地址说的对象存放在内存中的地址
附图
在这里插入图片描述
举例:
在这里插入图片描述
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_40645193/article/details/105726967