reversing keys/values - create new instance of HashMap

Posted by stck777 on Stack Overflow See other posts from Stack Overflow or by stck777
Published on 2010-03-19T07:39:21Z Indexed on 2010/03/19 7:41 UTC
Read the original article Hit count: 264

Filed under:
|

I’ve got an existing instance of HashMap simply called sale (it is Map>) I use it to log customers and items history.

Is there a way to create a new instance of HashMap, that effectively reverses this usage? i.e will show each item purchased as a unique key and the corresponding value as a String set of the customers that have purchased that product. I suspect there is a simple process using keySet() in some way to iterate over the sales map but I just can’t see how to do this. Any help would be much appreciated.

© Stack Overflow or respective owner

Related posts about hashmap

Related posts about java