問題描述
我需要的是一個允許多個鍵訪問單個對象的集合.
What I need is a collection which allows multiple keys to access a single object.
我需要對此對象進行頻繁的更改.
I need to apply frequent alterations to this object.
它還必須對 500k+ 個條目有效.
It also must be efficient for 500k+ entries.
推薦答案
java.util.Map<K,V>
的任何實現都可以做到這一點 - 沒有限制 在單獨的鍵下可以添加特定值多少次:
Any implementation of java.util.Map<K,V>
will do this - there is no restriction on how many times a particular value can be added under separate keys:
Map<String,Integer> m = new HashMap<String, Integer>();
m.put("Hello", 5);
m.put("World", 5);
System.out.println(m); // { Hello->5, World->5 }
如果您想要一個單一鍵與多個值相關聯的地圖,這稱為 多地圖,您可以從 google java 集合 API 或來自 Apache的commons-collections
If you want a map where a single key is associated with multiple values, this is called a multi-map and you can get one from the google java collections API or from Apache's commons-collections
這篇關于需要一個對一個值具有多個鍵的 Java 映射/表.值通常會改變的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!