java集合当中List的三种遍历方式

package lx;


import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;


class Demo01{
public static void main(String[] args) {


List a = new ArrayList();
a.add("A");
a.add("B");
a.add("C");
a.add("D");

List b = new ArrayList();
a.add("1");
a.add("2");
a.add("3");
a.addAll(b);
a.set(2, "E");
System.out.println(a);
ListIterator listIterator = a.listIterator();//迭代器
while(listIterator.hasNext()){//正向遍历
Object object = listIterator.next();
System.out.print(object);
}
System.out.println();
while(listIterator.hasPrevious()){//反向遍历
Object object = listIterator.previous();
System.out.print(object);
}
System.out.println();
for(int i=0;i System.out.print(a.get(i));
}
}


}

你可能感兴趣的:(java_Std)