I am trying to link the value of a key to another key's value but cannot seem to get it working.
For example, if I'm creating a HashMap and adding a key-value pair ("x", 0) to it. I then want to be able to add other keys mapped to the same value as the first one.
So if I have ("x", map.get("y")) and ("y", 0) I want to be able somehow to link it. So that if I now update a value for "y" key like that ("y", 10), then I expect that map.get("x") should also return 10.
HashMap<String, Integer> map = new HashMap<>();
map.put("x", 0);
map.put("y", 0);
//I now somehow want to link the value of x so its dependent on y
System.out.println(map.get("x"));
//Should return 0
map.put("y", 10);
System.out.println(map.get("x"));
//Should return 10 now
I can't figure out how to get this working as x always gets the value of what y is now, and not what y is at the time of printing the value.