官方文档描述是“Returns the previous element in the list and moves the cursor position backwards.”
即:返回前一个元素,并将迭代器回退。
但是我debug时发现,它返回的似乎是当前元素。
举例:
LinkedList<Integer> nums = new LinkedList<Integer>();
for(int i = 0; i < 10; ++i) nums.add(2*i);
ListIterator<Integer> itr = nums.listIterator();
for(;itr.hasNext();) itr.next();//遍历1
for(;itr.hasPrevious();)//遍历2
System.out.print(itr.previous()+" ");
首先nums存储的值是0,2,4,6,8,10,12,14,16,18
“遍历1”执行完毕之后,itr指向的应该是元素18
那么,假如按官方文档所说,“遍历2”打印的第一个元素应该是16
但是,实际上“遍历2”打印的结果是
18 16 14 12 10 8 6 4 2 0
是官方文档描述有误吗?