How can I identify if 2 Hashmaps have Objects with Common Ids

Asked

Viewed 30 times

0

Right now I’m playing a card game, in which each Player has an inventory of his Cards.

I am now trying to create a Deck and my goal is to make the Cards that are already in the Deck not appear on the inventory side so I tried using the following and code:

for (HashMap<String, String> cartaInventario : listaCartasInventario) {
                for (HashMap<String, String> cartaDeckInventario : listaCartasDeckInventario) {
                    if(cartaInventario.get(Config.TAG_ID_CARTA_INVENTARIO) != cartaDeckInventario.get(Config.TAG_ID_CARTA_DECKINVENTARIO))
                    {
                        cartasInventario.add(cartaInventario.get(Config.TAG_ID_CARTA_INVENTARIO));
                    }
                }
            }

This code does not yet work, my question is whether there is any other more effective way to do this check such as using lambda Expressions.

  • Hello, post the code in the question and not a print. There is an option to insert the code.

  • I’m sorry, my mistake

1 answer

0

Problem solved.

for (HashMap<String, String> cartaInventario : listaCartasInventario) {
        cartasInventario.add(cartaInventario.get(Config.TAG_ID_CARTA_INVENTARIO));
        for (HashMap<String, String> cartaDeckInventario : listaCartasDeckInventario) {
            if (cartaInventario.get(Config.TAG_ID_CARTA_INVENTARIO)
                    .equals(cartaDeckInventario.get(Config.TAG_ID_CARTA_DECKINVENTARIO))) {
                cartasInventario.remove(cartaInventario.get(Config.TAG_ID_CARTA_INVENTARIO));
                break;
            }
        }
    }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.