Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我的树图是
Map<String, Double> restrMap = new TreeMap<String, Double>();
将以下两个值添加到 treeMap 时,它只显示一个。第二个值,当更新第一个值时。
6, 8.00 6, 5.00
如何为同一个键添加两个值,可能在不同的行中?
如果要向同一个键添加多个值,请考虑使用列表映射。
Map<String, List<Double>> restrMap = new TreeMap<String, List<Double>>();
Java 没有多重映射,但您可以在映射值中使用另一个容器。
映射只有一个值与特定键关联。
如果你想要几个值,你可以:
Map<Key, Set<Value>>