1
I got the following HashMap
:
HashMap<Integer,HashMap<Integer,ArrayList<Integer>>> hm = new HashMap<>();
When I do this:
Set<Integer> keys = hm.keySet();
for(int i : keys) System.out.println(i + ": " +hm.get(i));
I have an output like:
2: {2=[1, 2, 3, 4]}
How can I walk the HashMap
to have access to the keys and values of the HashMap
inland?
Thanks for the help. gives me an error in the first line of your code: "Wrong number of type Arguments: required: 2"
– Hugo Machado
This code has not been tested by any ide, so you should have some attention to the code, error in
etry
- staysentry
– jsantos1991
Yeah, I figured that out, and I fixed it. I think that in the first line of your code the 'Hashmap' has to leave and is: 'for(Map.Entry<Integer,Hashmap<Integer,Arraylist<Integer>>> Kv: hm.entryset()){'
– Hugo Machado
@Hugomachado sees now
– Math
That’s how it worked ! Thanks for the help :D Just one more question later, I can go through the last Arraylist at the end?
– Hugo Machado
for (int valor : kvv.getValue()){
 System.out.println("arrayListvalores: "+ valor);
}
– Jorge B.
Yes it follows the same logic creates the list, assigns to that list the value of kvv.getvalue and then just go through
– jsantos1991
I’ll edit the question and if you can see if I’m doing something wrong I’d appreciate it.
– Hugo Machado
@Hugomachado put the code there
– Jorge B.
I was distracted didn’t see it. Thanks @Jorgeb. it worked ;)
– Hugo Machado
@Hugomachado reversed your question because the "correction" you put is the answer you find here.
– Jorge B.