Question: Write a method called reverse that accepts a map from strings to strings as a parameter and returns a new map that is the reverse

Write a method called reverse that accepts a map from strings to strings as a parameter and returns a new map that is the reverse of the original. The reverse of a map is a new map that uses the values from the original as its keys and the keys from the original as its values. Since a map’s values need not be unique but its keys must be, you should have each value map to a set of keys. In other words, if the original map maps keys of type to values of type, the new map should map keys of type to values that are Sets containing elements of type . For example, the map {42 = Marty, 81 = Sue, 17 = Ed, 31=Dave, 56=Ed, 3=Marty, 29 = Ed} has a reverse of {Marty=[42, 3], Sue = [81], Ed = [17, 56, 29], Dave = [31]}. (The order of the keys and values does not matter.)

Step by Step Solution

3.57 Rating (175 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

public static Map reverse Map ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Building Java Programs A Back to Basics Approach Questions!