Remove subArray from a Main Array

1

I have two main Arrays ( listaInformacoesNota , listaInformacoesPedidosPostgreSQL ) with N subArrays each, these subArrays have items in common and a different item only, I did the following to compare these each subArray:

for (List conteudoNotas : listaInformacoesNota){
    for (List conteudoPedidos : listaInformacoesPedidoPostgreSQL){
        if (conteudoNotas.get(3).toString().equals(conteudoPedidos.get(2).toString()) && conteudoNotas.get(4).toString().equals(conteudoPedidos.get(4).toString())){
            if (conteudoNotas.get(1).toString().equals(conteudoPedidos.get(1).toString()) && conteudoNotas.get(2).toString().equals(conteudoPedidos.get(3).toString())){
             \Aqui eu precisaria remover o subArray (conteudoNotas) do Array principal (listaInformacoesNota)
            }
        }
    }
}

I need to remove from the main Array% with% subArray listaInformacoesNota that fits the conditions, so that it is not compared again with any other subArray.

    
asked by anonymous 15.09.2017 / 14:12

1 answer

3

To remove an item from the list, in the middle of the iteration, use the Iterator.

Iterator<List> it = listaInformacoesNota.iterator();
while (it.hasNext()) {
    List conteudoNotas = it.next();
    for (List conteudoPedidos : listaInformacoesPedidoPostgreSQL) {
        if (conteudoNotas.get(3).toString().equals(conteudoPedidos.get(2).toString()) && conteudoNotas.get(4).toString().equals(conteudoPedidos.get(4).toString())) {
            if (conteudoNotas.get(1).toString().equals(conteudoPedidos.get(1).toString()) && conteudoNotas.get(2).toString().equals(conteudoPedidos.get(3).toString())) {
                it.remove();
            }
        }
    }
}

Note: I strongly recommend that you create classes for InformationNote and RequestData and use object lists of these classes instead of list lists. In these classes you would put attributes with meaningful names to store what would be these get (1), get (2), get (3) ...

For example:

if (conteudoNota.getOrigem().equals(informacaoPedido.getDestino()) && conteudoNota.getCodigo().equals(informacaoPedido.getCodigo())...
    
15.09.2017 / 20:24