我想根据其字段值获取一个特定的枚举.
枚举:
public enum CrimeCategory {
ASBO ("Anti Social BehavIoUr"),BURG ("Burglary"),CRIMDAM ("Criminal Damage And Arson"),DRUGS ("Drugs"),OTHTHEFT ("Other Theft"),PUPDISOR ("Public Disorder And Weapons"),ROBBERY ("Robbery"),SHOPLIF ("Shoplifting"),VEHICLE ("Vehicle Crime"),VIOLENT ("Violent Crime"),OTHER ("Other Crime");
private String category;
private CrimeCategory (String category) {
this.category = category;
}
public String returnString() {
return category;
}
}
获得新的枚举:
aStringRecivedFromJson = "Anti Social BehavIoUr"
CrimeCategory crimeCategoryEnum;
crimeCategoryEnum = CrimeCategory.valueOf(aStringRecivedFromJson);
我一直在试图找出一个方法,以便上面提供一个枚举,以便它可以通过与其他犯罪信息一起散布在Hashmap中.
预期成果:ASBO