Iterator 只能向前移动
ListIterator 却能双向移动
ListIterator.nextIndex() //得到下一个索引
ListIterator.previousIndex() //得到当前的索引ListIterator.set() //替换最后一个访问的元素public static void main(String[] args) { // TODO Auto-generated method stub List list = new ArrayList(); list.add("cat"); list.add("dog"); list.add("panda"); ListIterator listIterator = list.listIterator(1); //从索引为1开始 while(listIterator.hasNext()){ String name = (String)listIterator.next(); System.out.println(name + ",nextIndex:" + listIterator.nextIndex() +",previousIndex:"+listIterator.previousIndex()); listIterator.set(name + "set后"); } listIterator = list.listIterator(1); //从索引为1开始 while(listIterator.hasNext()){ String name = (String)listIterator.next(); System.out.println(name); }}//输出:dog,nextIndex:2,previousIndex:1panda,nextIndex:3,previousIndex:2dogset后pandaset后