import java.util.ArrayList; import java.util.List; import java.util.ListIterator; public class TestDemo { public static void main(String[] args) { List<Integer> list = new ArrayList<Integer>(); list.add(1); list.add(5); list.add(2); list.add(4); list.add(3); System.out.println("----------for循环-----------"); int size = list.size(); for(int i=0;i<size;i++){ System.out.print(list.get(i)+" "); } System.out.println(); System.out.println("--------for each 循环--------"); for(int a:list){ System.out.print(a+" "); } System.out.println(); System.out.println("-------单项迭代器---------"); java.util.Iterator<Integer> it = list.iterator(); while(it.hasNext()){ System.out.print(it.next() + " "); } System.out.println(); System.out.println("--------双向迭代器---------"); ListIterator<Integer> lte = list.listIterator(); while(lte.hasNext()){ System.out.print(lte.next() + " "); } System.out.println(); while(lte.hasPrevious()){ System.out.print(lte.previous()+" "); } } }