public static void main(String[] args) {
List l1 = new ArrayList();
List<Object> l2 = new ArrayList();
//添加
l1.add(789);
l1.add(666);
l1.add("sdf");
l1.add("0fr");
l1.add(123);
System.out.println("add(e) "+l1);
l1.add(2, "yyy");
System.out.println("add(i,e) "+l1);
l2.addAll(l1);
System.out.println("l2 "+l2);
//删除
l2.remove(0);
l2.remove("yyy");
System.out.println("l2 "+l2);
//替换
l1.set(2, "ababa");
//查询
//1.get(index)
System.out.print("查询 ");
for (int i = 0; i < l1.size(); i++) {
System.out.print(l1.get(i)+" ");
}System.out.println();
//2.indexof()、lastIndexOf()
int index = l1.indexOf("ababa");
System.out.print(index);
int index2 = l1.lastIndexOf("ababa");
System.out.print(index2);
//遍历
//1.反向 l1.size()注意不要遗漏,否则什么都不输出,这里也不需要减一
ListIterator lt = l1.listIterator(l1.size());
while(lt.hasPrevious()) {
Object obj = lt.previous();
System.out.print(obj+" "+lt.previousIndex()+" ");
}System.out.println();
//2.正向,输出的是此元素的下一个下标
while(lt.hasNext()) {
Object obj = lt.next();
System.out.print(obj+" "+lt.nextIndex()+" ");
}
for (Object ob : l2) {
System.out.print(ob+"-");
}
//修改某个值
ListIterator<Object> it = l2.listIterator();
while(it.hasNext()) {
Object next = it.next();
if("sdf".equals(next)) {
int i = l2.indexOf(index);
l2.set(i, "123123123");
}
}
System.out.println(l2);
}