I'm looking to build a hash table where multiple String keys that share the same Byte array value are merged into one value with multiple keys. This is so the value isn't stored over and over again with different values. Adding a key with a value should also overwrite any existing key with the same name, but keep the value if it has a different key as well, but delete it when there is no other key.
EDIT: How do I build this data structure? For example, if I insert "hello" with a value, then add "World" with the same value, I would like the structure to something along the lines of [[Hello, World], Value] instead of [Hello, Value], [World, Value]. I tried using a list as my hashkey, but found I couldnt recall the value. Here is my code:
HashMap<List<String>, byte[]> map = new HashMap<List<String>, byte[]>();
public void storeByte (String id, int value) {
byte[] byteValue = new byte[value];
ArrayList<String> idlist = new ArrayList<String>();
idlist.add(id);
map.put(idlist, byteValue);
System.out.println(map);
}
public byte[] fetchByte(String id) {
ArrayList<String> idlistsearch = new ArrayList<String>();
idlistsearch.add(id);
byte[] output = map.get(id);
if(map.containsKey(idlistsearch)){
output = map.get(id);
} else {
return null;
}
return output;
I hope this makes sense,
Thank you.