提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
使用ListIterator获取上一个和下一个索引
import java.util.ListIterator;//n o w j a v a . c o m - 时代Java 提 供 import java.util.ArrayList; public class Main { public static void main(String[] args) { ArrayList aList = new ArrayList(); aList.add("1"); aList.add("2"); aList.add("3"); aList.add("4"); aList.add("5"); ListIterator listIterator = aList.listIterator(); System.out.println("Previous Index is : " + listIterator.previousIndex()); System.out.println("Next Index is : " + listIterator.nextIndex()); listIterator.next(); /** 来 自 N o w J a v a . c o m**/ System.out.println("After increasing current position by one element : ");