I am trying to map and array of ints to an int value. I know that int[] wont work as keys. I have tried List however that doesn't work as well. Is there anyway I can do this? Thanks.
Here is my failed attempt:
private void createMap(){
List<Integer> state_action_pair = new ArrayList<Integer>();
for(int i=0;i<this.stateActionTable.length;i++){
for(int j=0;j<this.stateActionTable[0].length;j++){
state_action_pair.add(this.stateActionTable[i][j]);
}
this.stateActionMap.put(state_action_pair, i);
state_action_pair.clear();
}
}
map.get(Arrays.asList(1, 2, 3)). That is impossible to do with an array, becausenew int[] {1, 2, 3}won't ever be equal to the array used as key in the map.HashMap/HashSetdocs both say that behaviour is undefined if the keys are modified. If the list is immutable, it can be safely used as a key.