import java.util.*;class  iterator
{
public static void main(String[] args) 
{
List nodes2= new ArrayList(); nodes2.add("a6");
nodes2.add("a2");
nodes2.add("a4");
nodes2.add("a3");
nodes2.add("a5");
nodes2.add("f0"); ListIterator it2 = nodes2.listIterator();

while(it2.hasPrevious()){
String obj1 = (String)it2.previous();
System.out.println(obj1);
} }
}

解决方案 »

  1.   

    没有上一个,while循环就没进去
      

  2.   

    ??不会是先这样吧??

    while(it2.hasNext())
    {
    it2.next();
    }
      

  3.   

    list支持index访问,何必用iterator?
      

  4.   

    iterator 返回的对象是无序的,正向反向没啥意义
      

  5.   

    恩,应该顺序的,否则怎么会NEXT
      

  6.   

    trumplet(检查) 为什么说是无序的呢?是有序的阿
    API:
    listIterator() 
              Returns a list iterator of the elements in this list (in proper sequence). 
      

  7.   

    就像rs一样,指针指向第一条之前,hasNext()方法之后才是第一条数据那么在生成迭代器对象之后,hasPrevious()根本没值,你还反向做什么?
      

  8.   

    ListIterator it2 = nodes2.listIterator(nodes2.size()-1);但要注意,遍历的时候,需要先调用一次 it2.next(),然后再反复调用 it2.previous()
      

  9.   

    maquan('ma:kju):
    ListIterator it2 = nodes2.listIterator(nodes2.size()-1);但要注意,遍历的时候,需要先调用一次 it2.next(),然后再反复调用 it2.previous()-------------事实上不需要先调用一次next(), 在API doc中,ListIterator里有这么一段:
    Throws:
        IndexOutOfBoundsException - if the specified index is out of range (index < 0 || index > size()).
    也就是说index是可以等于nodes2.size()的。而将nodes2.size()作为参数传给那个函数,所得到的迭代器指向的是最后一个元素的下一个位置,因此可以直接调用previous().