- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
MultiMap in Java
85 Lectures 6 hours
Multimap is a general method to bind the keys with random multiple values. The Multimap framework in Guava has methods that help in dealing with mapping keys to multiple values. Multimap can be visualized as a framework that −
- Is a collection of mapping from one key to one specific value
- Is a collection of mapping from unique key to multiple values, i.e. collection of values.
It can be implemented in places that use Map<K, Collection<V>>.
Advantages of Multimap
- An empty collection need not be populated before added a key value pair with the help of the function ‘put’.
- The ‘get’ method doesn’t return a null, except for cases of empty collection.
- A key is present in Multimap if and only if it has been mapped to at least one value.
- If a key in a multimap has no associated values, that key is removed implicitly from multimap.
- The number of values in the multimap can be obtained with the help of the function ‘size’.
Certain functions in Multimap −
- Multimap.containsKey(key) − This function returns a true when there is an element/mapping associated with the key that is passed as a parameter to this function. Otherwise, this function returns false.
- Multimap.entries() − This function returns all the associated values for all the keys with respect to the multimap.
Note − If we wish to obtain the entries as a key-value pair, the ‘asMap().entrySet()’ can be used. Multimap.size(): This function returns the total number of entries in the Multimap in its entirety. It doesn’t give the distinct keys, just all of them.
Distinct keys can be obtained by using the Multimap.keySet().size().
- multimap::begin() and multimap::end() in C++ STL
- multimap::crbegin() and multimap::crend() in C++ STL
- multimap::cbegin() and multimap::cend() in C++ STL
- multimap::swap() in C++ STL
- multimap::operator= in C++ STL
- multimap::erase() in C++ STL
- multimap rend in C++ STL
- multimap rbegin in C++ STL
- multimap maxsize() in C++ STL
- multimap insert() in C++ STL
- multimap::emplace() in C++ STL
- multimap::emplace_hint() in C++ STL
- multimap::count() in C++ STL
- multimap key_comp() in C++ STL
- multimap find( ) in C++ STL