Invert a Map e.g 1: {a,b} 2: {c,d} becomes a:1 b:1 c:2 d2
Anónimo
Since no one has answered the question, I figure I'll throw in my 2 cents. It seems fairly simple; if you're using java (and probably most OO languages), you have access to all the keys that you've inserted into the map through a function call. Simply iterate through your keys to get the value from the map for each key, and put that value in a temporary variable (I'll call it tempValue). Then, save the key before it's destroyed in the next step (let's call it tempKey). Then, remove the entry from the hash table that correlated to that value (i.e., map.remove(key) I think it is). Now, do a map.put(tempValue, tempKey). You've now done your first iteration; repeat these steps for the rest of the hash's keys and you're done.