InterviewSolution
| 1. |
Describe various implementations of the Map interface and their use case differences and map hierarchy diagram? |
|
Answer» 1. HASHMAP:
2. LinkedHashMap Linked HashMap is an implementation of the map interface along with the hashing algorithms it also supports the ordering according to the insertion order. Code Snippet: Map map = new LinkedHashMap(); Use Case: LinkedHashMap is useful whenever we need to maintain the ordering of keys to match the ordering of insertion. along with that when we need to handle the caching mechanism. 3. TreeMap TreeMap is an implementation of the map interface, where it follows the Tree data structure which is RedBlack Tree implementation and follows the natural order Code Snippet: Map map = new TreeMap(); Use case: One can use the TreeMap when we need the natural ordering, or we need to sort the record alphabetically or ascending and descending order. |
|