I would say that the essence of hasmap keys for index access purposes is nothing more than hacking: creating a wrapper class for keys around the key value so that the key wrapper object becomes a hash key for accessing the index, so You can access and change the value of the key shell object for your specific needs:
public class KeyWrapper<T>{ private T key; public KeyWrapper(T key){ this.key=key; } public void rename(T newkey){ this.key=newkey; } }
Example
Example
HashMap<KeyWrapper,String> hashmap=new HashMap<>(); KeyWrapper key=new KeyWrapper("cool-key"); hashmap.put(key,"value"); key.rename("cool-key-renamed");
LiNKeR Jul 28 '19 at 18:15 2019-07-28 18:15
source share