search

Home  >  Q&A  >  body text

这个Java的list运行的时候为什么会报错?

for (car_gps car_gps : locList) {
                        if(car_gps.getGps_lat().contains("E")||car_gps.getGps_lng().contains("E")){  //排除异常坐标
                              locList.remove(car_gps);
                            
                          }
                    }
PHP中文网PHP中文网2813 days ago404

reply all(2)I'll reply

  • PHP中文网

    PHP中文网2017-04-18 10:24:29

    When foreach loops a list, you cannot remove elements of the looped list in the loop body. You can use the iterator method, or record the index of the element to be deleted first, and then delete the elements with corresponding indexes after the for loop ends.

    reply
    0
  • PHP中文网

    PHP中文网2017-04-18 10:24:29

    Brother, how do we know what is in locList? What is the car_gps object? At least give me an error message

    reply
    0
  • Cancelreply