ArrayList常用方法啊
时间: 2024-06-12 14:09:46 浏览: 7
ArrayList是Java中常用的动态数组。常用方法包括:
1. add(Object o):在末尾添加一个元素o;
2. add(int index, Object o):在指定位置添加一个元素o;
3. remove(Object o):移除指定元素o;
4. remove(int index):移除指定位置的元素;
5. clear():清空所有元素;
6. get(int index):返回指定位置的元素;
7. set(int index, Object o):替换指定位置的元素为o;
8. size():返回元素个数;
9. isEmpty():判断是否为空;
10. contains(Object o):判断是否包含指定元素。
相关问题
arraylist常用方法
ArrayList常用方法包括:
1. add(Object element): 向列表末尾添加指定的元素。
2. get(int index): 返回列表中指定位置的元素。
3. remove(int index): 移除列表中指定位置的元素。
4. size(): 返回列表中的元素个数。
5. clear(): 清空列表中的所有元素。
6. contains(Object element): 判断列表是否包含指定的元素。
7. indexOf(Object element): 返回列表中第一次出现指定元素的索引,如果列表中不包含该元素,则返回-1。
8. lastIndexOf(Object element): 返回列表中最后一次出现指定元素的索引,如果列表中不包含该元素,则返回-1。
9. isEmpty(): 判断列表是否为空。
ArrayList常用方法
ArrayList是Java中常用的集合类,提供了很多实用的方法,例如:
1. add(Object obj):向ArrayList中添加元素
2. add(int index, Object obj):在指定位置插入元素
3. remove(Object obj):删除元素
4. remove(int index):根据索引删除元素
5. get(int index):获取指定索引位置的元素
6. set(int index, Object obj):设置指定索引位置的元素
7. size():获取ArrayList的大小
8. clear():清空ArrayList中的元素
9. indexOf(Object obj):查找元素在ArrayList中的索引位置
10. toArray():将ArrayList转化为数组
以上是ArrayList中常用的方法,还有很多其他的方法可以在开发中灵活运用。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![text/plain](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)