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); 更改下标元素
来源: http://www.bubuko.com/infodetail-3172431.html