![](https://images2017.cnblogs.com/blog/725061/201711/725061-20171122174036305-558146725.png)
import java.util.ArrayList;
import java.util.ListIterator;
public class test {
public static void main(String args[])
{
ArrayList<elem> list=new ArrayList<elem>(100);
for(int i=0;i<100;i++)
list.add(new elem(i));
ListIterator<elem> iterator=list.listIterator();
while(iterator.hasNext()){
((elem) iterator.next()).geti();
}
try{
list.get(50).geti();
list.get(102).geti();
}
catch (IndexOutOfBoundsException e) {
// TODO: handle exception
System.out.println("out");
}
}
}
class elem{
private int i;
elem(int i){
this.i =i;
}
void geti(){
System.out.println(i);
}
}
![](https://images2017.cnblogs.com/blog/725061/201711/725061-20171122174111743-1773462354.png)