[英]How do I add multiple values to the same key in a TreeMap?
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. 在将以下两个值添加到treeMap时,它只显示一个。 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? 如何为同一个键添加两个值,可能在不同的行中?
如果要向同一个键添加多个值,请考虑使用列表映射。
Map<String, List<Double>> restrMap = new TreeMap<String, List<Double>>();
A map has only one value associated to a specific key. 地图只有一个与特定键关联的值。
If you want several values, you can: 如果您想要多个值,您可以:
Java没有multimap,但您可以在map值中使用另一个容器。
Map<String, List<Double>> restrMap = new TreeMap<String, List<Double>>();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.