ArrayIndexOutOfBoundsException when using the ArrayList's iterator

后端 未结 8 1199
甜味超标
甜味超标 2020-12-02 06:36

Right now, I have a program containing a piece of code that looks like this:

while (arrayList.iterator().hasNext()) {
     //value is equal to a String value         


        
8条回答
  •  旧巷少年郎
    2020-12-02 07:13

    While I agree that the accepted answer is usually the best solution and definitely easier to use, I noticed no one displayed the proper usage of the iterator. So here is a quick example:

    Iterator it = arrayList.iterator();
    while(it.hasNext())
    {
        Object obj = it.next();
        //Do something with obj
    }
    
        

    提交回复
    热议问题