Reputation: 434
I'm looking for a way to map multiple keys to the same value without using extra memory by adding this value twice. Normally you would just do:
Map<Integer, Integer> map = new HashMap<>();
map.put(065,600);
map.put(070,600);
But it is my understanding that the value 600 is now stored in memory twice. Is there a way to avoid this such that they point to the exact same value? Thanks a bunch ! Peace out
Upvotes: 2
Views: 1645
Reputation: 10727
Try this:
Map<Integer, Integer> map = new HashMap<>();
Integer i = 600;
map.put(065,i);
map.put(070,i);
Upvotes: 2