4
It is possible to create a MAP<>
within another MAP<>
?
like this code:
private Map<String, Map<String,Object>> mapTESTE = new HashMap<String, Map<String,Object>>();
If yes:
How I enter values in the second MAP<>?
is a good practice?
I need something like this because both the key of the first MAP<> and the key of the second should not be repeated.
Other ways to implement something like this are welcome
_____**Edit**_____
I need to update data every five minutes
the structure is something like this: //
id1:
nº do produto1 || dados do produto1
nº do produto2 || dados do produto2
.......
nº do produtoX || dados do produtoX
id2:
nº do produto1 || dados do produto1
nº do produto2 || dados do produto2
.......
nº do produtoX || dados do produtoX
id3:
nº do produto1 || dados do produto1
nº do produto2 || dados do produto2
.......
nº do produtoX || dados do produtoX
id’s do not repeat, this is when an equal arrives I have to update the values inside the MAP<>
and the product numbers cannot be repeated either
Basically the values that suffer most updates is the product data.
Possibly this is not the best way to do this, but I confess that I especially like to use MAP because of automatically updated values by the latest and do not let repeat keys
"both the key of the first MAP and the key of the second should not be repeated" You mean, each pair cannot repeat itself, right? Ex.:
(a,c) (a,d) (b,c) (b,d)
can? And(a, b) (b, a)
can? Or even(a, a)
. If possible, clarify better what your actual problem is, not just your attempt at a solution (i.e. contextualize).– mgibsonbr
According to its edition, it seems to me that a map of maps as you proposed is a good alternative yes. The ids do not repeat in the main map, and the product numbers do not repeat in each sub-map. The product data, these are independent of id to id, right? Ex.:
(id1,produto1,dadoX) (id2,produto1,dadoY)
So if you need to update theid1
, will stay(id1,produto1,dadoZ) (id2,produto1,dadoY)
- the other data for the same product do not change. Check?– mgibsonbr
Yes exactly that, the product data is completely related to the product number and the product number is completely related to the id, There is no way these numbers repeat themselves when they repeat it is because the product data has changed so I have to go through and just add a "new data" that as it is a MAP automatically replaces. In your opinion my thinking is correct?
– jsantos1991
Yes, especially as "the product number is completely related to the id", so there is no conflict. I believe everything is correct then.
– mgibsonbr