Is there a replacement for Arrays with enums as indexes?
c, enums, java
Solution
Yes there is a fairly simple one. Use HashMaps.
Map<CustomEnum, Object> hashMap = new HashMap<>();
//Basic usage
hashMap.put(CustomEnumID, ObjectValue);
ObjectValue obj = hashMap.get(CustumEnumID); //Returns the value from the above line
hashMap.containsValue(CustomEnumID); //Return true or false
Problem
I used to use enums as indexes in C. (each enum something like an alias for an int value) Example: ``` typedef enum {DOG, CAT, MOUSE} ANIMALS; int[3] age; ... age[DOG] = 4; age[CAT] = 3; age[MOUSE] = 10; ``` With enums as indexes, I can always be sure that I am updating the right cell. Furthermore, I need the simplicity of arrays as well. I would like to do the same in Java. But, I cant seem to find a simple replacement. Does anyone know a replacement that can be used the same way as Array+enum combo did in C?