顺序表的一些重要操作

試著忘記壹切 提交于 2019-11-28 18:29:05

ArrayList 常用操作:
构造方法:
ArrayList(); 构造空的·顺序表,容量是默认容量
ArrayList(int capacity); 构造空的顺序表,容量是Capacity
ArrayList(Collection c); 构造一个顺序表,把C中的所有元素放到顺序表中
List<Integer> origin=Arrays.asList(1,2,3,4,5);
ArrayList<Integer> list=new ArrayList<>(origin);
常用方法:
add(E element); 尾插数据
add(int index,E element); 把元素插入到index位置
remove(Object o); 删除顺序表中第一个e
remove(int index); 删除顺序表中的下标index位置的元素
contains(E e); 判断e在不在顺序表中(查找)
indexOf(E e); 从前数下标
lastIndexOf(E e); 从后数下标
get(int index); 返回下标元素
set(int index,E e); 更改下标元素

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!