Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MultiMap vs MultiValue Map

At one place i have to use a map with many values mapped to a single key, so i was wondering whether there is any significant performance distinction between using HashMap of key, list and MultiMap of key , values in java.

like image 928
r15habh Avatar asked Apr 29 '11 09:04

r15habh


People also ask

What is a Multivalue map?

A MultiValueMap decorates another map, allowing it to have more than one value for a key. A MultiMap is a Map with slightly different semantics. Putting a value into the map will add the value to a Collection at that key. Getting a value will return a Collection, holding all the values put to that key.

What is difference between MAP and MultiValueMap?

A map cannot contain duplicate keys; each key can map to at most one value. So in a MultivaluedMap you can insert 0, 1, 2, 3 or more objects related to the same key. In a Map you can insert exactly 1 object related to a key.

What is MultiMap guava?

A Multimap is a new collection type that is found in Google's Guava library for Java. A Multimap can store more than one value against a key. Both the keys and the values are stored in a collection, and considered to be alternates for Map<K, List<V>> or Map<K, Set<V>> (standard JDK Collections Framework).

How do you use a Multivalue map?

Method SummaryAdd the given single value to the current list of values for the given key. Add all the values of the given list to the current list of values for the given key. Add all the values of the given MultiValueMap to the current values. Add the given value, only when the map does not contain the given key.


1 Answers

You can try it but I doubt there is much difference as it does much the same thing.

IMHO The advantage is simpler/clearer code which is usually more important than performance.

like image 90
Peter Lawrey Avatar answered Sep 17 '22 16:09

Peter Lawrey