Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add multiple values to the same key in a TreeMap?

Tags:

java

treemaps

My tree Map is

Map<String, Double> restrMap = new TreeMap<String, Double>(); 

While adding the below two value to the treeMap, it only shows one. The second value, when comes updates the first one.

6, 8.00
6, 5.00

How can I add two values for the same key, perhaps in different rows?

like image 579
Shubham Ranka Avatar asked Oct 26 '25 18:10

Shubham Ranka


1 Answers

If you are adding multiple values to the same key, consider having a Map of Lists.

Map<String, List<Double>> restrMap = new TreeMap<String, List<Double>>();
like image 84
Marc Avatar answered Oct 29 '25 09:10

Marc



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!