2
How can I traverse the values of a Hashmap through a certain key?
An example to illustrate: I have a Hashmap called values, with a key that is an id represented by String and a value that is an integer.
HashMap<String, Integer> valores = new HashMap<String,Integer>();
valores.put("Id01",13);
valores.put("Id02",4);
valores.put("Id01",37);
valores.put("Id01",49);
valores.put("Id02",9);
valores.put("Id01",78);
valores.put("Id03",5);
valores.put("Id01",90);
How do I, for example, loop/for across the Hashmap and print all Hashmap values belonging to the "Id01" key? Generating the following result on the console:
13
37
49
78
90
How, since it is not possible to have multiple equal keys in one
HashMap
?– Paulo Rodrigues
So I didn’t know. Thank you.
– Willian Simões