-1
A problem arose in an excerpt of the code, where it is stored in a variable Hashmap 2 different values, the problem is that the indexing as I understand it is done by the key, that is, it is not possible to have duplicated key. Follows the excerpt from the code in question:
HashMap contribuinteList = (HashMap) origem.get("ConstribuinteList");
idContribuinte = request.getParameter("idcontribuinte");
exercicio = gb.getYear();
contribuinteList.put(idContribuinte, exercicio);
What would be the best way to work in this situation, given that I can have more than 1 contributor ?
I didn’t understand the problem. If you can have more than one contributor, I understand that each one has a different ID, so just add in the map:
contribuinteList.put(idContribuinte1, exercicio1)
,contribuinteList.put(idContribuinte2, exercicio2)
, etc. I would only change the name tocontribuintes
, orcontribuinteMap
, sincecontribuinteList
may give the false impression that it is a list (List
,ArrayList
, etc), which is another completely different data structure– hkotsubo
Friend @Victor Henrique each contributor will have their own id, so there is to have duplicate key....
– Erick Luz
It is an import, so I can have "15336,2018" "15336,2019", the id can be repeated. In this case it would update the key, which could not occur, since I need the integrity of the data as entered.
– Victor Henrique