Reputation: 493
The code is in portuguese, i'm sorry about that.
I read in another question here at SO that the exception was being thrown because I was using progSelecionada.remove()
, so I changed toi iterator.remove()
but the error remains.
Can someone explain to me what I may be doing wrong?
final List<Programacao> programacoesASeremRemovidas = new ArrayList<Programacao>(
this.programacoesDaEscala.size());
programacoesASeremRemovidas.addAll(this.programacoesDaEscala);
final List<Programacao> programacoesEmpresas = Cache.getInstance().getProgramacoes(
this.empresasSelecionadas);
for (final Iterator<Programacao> iterator = programacoesEmpresas.iterator(); iterator.hasNext();)
{
final Programacao progSelecionada = iterator.next();
for (final Programacao progEmpresa : programacoesEmpresas)
{
if (progSelecionada.getId() == progEmpresa.getId())
{
iterator.remove();
}
}
}
Upvotes: 0
Views: 60
Reputation: 393831
You probably have a bug, since both your loops iterate on the same list programacoesEmpresas
, so even if you didn't get an exception, you would simply remove all the objects from the list (assuming you are not comparing Strings with ==
- I don't know what the type of getId()
is).
You can't modify that list while iterating over it with the enhanced for loop (which is what you do in the internal loop).
for (final Iterator iterator = programacoesEmpresas.iterator(); iterator.hasNext();)
and for (final Programacao progEmpresa : programacoesEmpresas)
Upvotes: 2