I want to have map in reverse direction which is mean I have lots of keys and only one value. I need this structure so when I search for one of the key I got the value.
I can use a simple Hash Map but it waste space because of storing value many times. I am looking for optimize and efficient implementation in java. I appreciate your suggestion.
HashMap should be used. when you put "cloth" into HashMap as a value, it is not duplicated in memory. just reference is written into HashMap.
String hat = "hat";
String dress = "dress";
String paths = "paths";
String scarf = "scarf";
String cloth = "cloth";
HashMap h = new HashMap();
h.put(hat,cloth);
h.put(paths,cloth);
h.put(dress,cloth);
h.put(scarf,cloth);
for this sample, memory keeps only cloth object for once.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With