Write a static method named mergeMapsToMultiMap that takes two Maps using String
ID: 644225 • Letter: W
Question
Write a static method named mergeMapsToMultiMap that takes two Maps using Strings as keys and Integers as values. The method should return a map that uses Strings as keys and has a LinkedList of Integers as a value (aka a MulitMap). The contents of the LinkedList should be the values pointed at by the keys in either input Map. For example, if map1 has the key "Apple" pointing at the Integer 12 and map2 has the key "Apple" pointing to the Integer 15, then the map returned by the method should have the key "Apple" pointing to a LinkedList containing the values [12,15]. (The order that the elements are added to this list does not matter). If a key is in only one Map, then its value should point to a LinkedList containing only that single value.
Explanation / Answer
If you wanted to merge the lists inside the HashMap. You could instead do this.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.