擅长:python、mysql、java
<p>对于实现<a href="http://download.oracle.com/javase/7/docs/api/java/util/List.html">^{<cd1>}</a>接口的集合,可以调用<a href="http://download.oracle.com/javase/7/docs/api/java/util/List.html#listIterator%28%29">^{<cd2>}</a>方法来获取<a href="http://download.oracle.com/javase/7/docs/api/java/util/ListIterator.html">^{<cd3>}</a>。迭代器(除其他外)有两个方法-<a href="http://download.oracle.com/javase/7/docs/api/java/util/ListIterator.html#nextIndex%28%29">^{<cd4>}</a>,用于获取索引;和<a href="http://download.oracle.com/javase/7/docs/api/java/util/ListIterator.html#next%28%29">^{<cd5>}</a>,用于获取值(与其他迭代器一样)。</p>
<p>因此,上述Python的Java等价物可能是:</p>
<pre><code>List<String> numbers = Arrays.asList("zero", "one", "two");
ListIterator<String> it = numbers.listIterator();
while (it.hasNext()) {
System.out.println(it.nextIndex() + " " + it.next());
}
</code></pre>
<p>它和Python一样,输出:</p>
<pre><code>0 zero
1 one
2 two
</code></pre>