I want to use enum
as keys and a object as value. Here is the sample code snippet:
public class DistributorAuditSection implements Comparable<DistributorAuditSection>{
private Map questionComponentsMap;
public Map getQuestionComponentsMap(){
return questionComponentsMap;
}
public void setQuestionComponentsMap(Integer key, Object questionComponents){
if((questionComponentsMap == null) || (questionComponentsMap != null && questionComponentsMap.isEmpty())){
this.questionComponentsMap = new HashMap<Integer,Object>();
}
this.questionComponentsMap.put(key,questionComponents);
}
}
It is now a normal hashmap with integer keys and and object as values. Now I want to change it to Enummap
. So that I can use the enum
keys. I also don't know how to retrieve the value using Enummap
.
It the same principle as
Map
Just Declareenum
and use it asKey
toEnumMap
.You can find more about
Enums
hereJust replace
new HashMap<Integer, Object>()
withnew EnumMap<MyEnum, Object>(MyEnum.class)
.