package com.sxt.listdemo;
import java.util.ArrayList;
import java.util.List;
/*
- List接口
- 该接口子类的特点: 有序, 可重复
- 该接口所特有的方法:
- 增加
-
void add(int index, E element)
-
boolean addAll(int index, Collection<? extends E> c)
- 删除
-
E remove(int index)
- 修改
-
E set(int index, E element)
- 查询[遍历]
-
E get(int index)
-
ListIterator<E> listIterator()
-
ListIterator<E> listIterator(int index)
- 获取
-
E get(int index)
-
int indexOf(Object o)
-
int lastIndexOf(Object o)
-
List<E> subList(int fromIndex, int toIndex)
*/
public class ListDemo01 {
public static void main(String[] args) {
List<String> list = new ArrayList<>();
list.add("张三");
list.add("李四");
list.add("王五");
list.add("赵六");
System.out.println(list);
list.add(2, "呵呵");
System.out.println(list);
System.out.println(list.remove(list.indexOf("呵呵")));
System.out.println(list);
list.set(list.indexOf("王五"), "老王");
System.out.println(list);
System.out.println(list.get(0));
System.out.println(list.lastIndexOf("老王"));
List<String> subList = list.subList(1, 3);
System.out.println(subList);
list.toArray();
}
}