Вопрос по java, hashtable – Многозначная хеш-таблица в Java

25

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceededsigh Mark Renouf
Error: User Rate Limit Exceeded Jonik
Error: User Rate Limit Exceeded Michael Myers♦
Error: User Rate Limit Exceeded Michael Myers♦
Error: User Rate Limit Exceeded Tom Hawtin - tackline

Ваш Ответ

6   ответов
4

Map<Object, List<Object>> multiMap = new HashMap<Object, List<Object>>();

  public void add(String key, Object o) {
    List<Object> list;
    if (multiMap.containsKey(key)) {
      list = multiMap.get(key);
      list.add(o);
    } else {
      list = new ArrayList<Object>();
      list.add(o);
      multiMap.put(key, list);
    }
  }
Error: User Rate Limit ExceededoneError: User Rate Limit Exceeded
6

Hashtable

Hashtable<String, String> ht = new Hashtable<String, String>();

ht.put("Answer", "42");
ht.put("Hello", "World");    // First value association for "Hello" key.
ht.put("Hello", "Mom");      // Second value association for "Hello" key.

for (Map.Entry<String, String> e : ht.entrySet()) {
  System.out.println(e);
}

"World", "Mom""Hello"Hashtable:

Answer=42
Hello=Mom

"Hello""World"Hashtable"Hello"MomHashtableHashtable.

Multimap:

Multimap<String, String> mm = HashMultimap.create();

mm.put("Answer", "42");
mm.put("Hello", "World");
mm.put("Hello", "Mom");

for (Map.Entry<String, String> e : mm.entries()) {
  System.out.println(e);
}

HashtableMultimap

Answer=42
Hello=Mom
Hello=World

"Hello""Mom""World"HashtableMultimap

Error: User Rate Limit Exceeded
1

Hashtable<Key, Value>Hashtable<Key, Vector<Value>>.

Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded
0

Map<Double,List<Object>> multiMap = new TreeMap<Double,List<Object>>();

for( int i= 0;i<15;i++)
{
    List<Object> myClassList = multiMap.get((double)i);
    if(myClassList == null)
    {
        myClassList = new ArrayList<Object>();
        multiMap.put((double) i,myClassList);
    }
    myClassList.add("Value "+ i);
}

List<Object> myClassList = multiMap.get((double)0);
if(myClassList == null)
{
    myClassList = new ArrayList<Object>();
    multiMap.put( (double) 0,myClassList);
}
myClassList.add("Value Duplicate");
for (Map.Entry entry : multiMap.entrySet()) 
{
  System.out.println("Key = " + entry.getKey() + ", Value = " +entry.getValue());
}
5

Multimap

(update:

Edit

Error: User Rate Limit Exceeded
21

Map<YourKeyObject, List<YourValueObject>>Multimap.

Example:
String key = "hello";
Multimap<String, Integer> myMap = HashMultimap.create();
myMap.put(key, 1);
myMap.put(key, 5000);
System.out.println(myMap.get(key)); // prints either "[1, 5000]" or "[5000, 1]"
myMap = ArrayListMultimap.create();
myMap.put(key, 1);
myMap.put(key, 5000);
System.out.println(myMap.get(key)); // always prints "[1, 5000]"

MultimapexactHashtableMultimapMultimapif you are using it on multiple threadsHashMapHashtable

Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded

Похожие вопросы