Ver Mensaje Individual
  #8 (permalink)  
Antiguo 03/05/2010, 03:33
GreenEyed
 
Fecha de Ingreso: octubre-2003
Mensajes: 3.578
Antigüedad: 20 años, 7 meses
Puntos: 51
Respuesta: Cambiar un objeto de clase en un ArrayList

Si recorres una coleccion con un bucle for-each, no puedes borrar elementos de ella mientras lo haces. Para poder borrar un elemento, lo que tienes que hacer es declarar y recorrer explicitamente la coleccion con un Iterator y usar el metodo remove() que tiene.

Lo explican en la documentación del bucle for-each, al final:
http://java.sun.com/j2se/1.5.0/docs/...e/foreach.html

Cita:
Unfortunately, you cannot use it everywhere. Consider, for example, the expurgate method. The program needs access to the iterator in order to remove the current element. The for-each loop hides the iterator, so you cannot call remove.
S!
__________________
Para obtener respuestas, pregunta de forma inteligente o si no, pregunta lo que quieras que yo contestaré lo que me dé la gana.