I want to get the enum value by name string,
this the enum code: package practice;
enum Mobile {
Samsung(400),
Nokia(250),
Motorola(325);
int price;
Mobile(int p) {
price = p;
}
int showPrice() {
return price;
}
}
I can get the class name and the name string
Class enumClass = Class.forName("practice.Mobile");
String name = "Samsung";
how can I get the Samsung value 400 only use enumClass and name? thanks a lot
Enum.valueOf(String)? e.gMobile.valueOf("Nokia")getPrice(), notshowPrice(), especially since the method doesn't actually show anything.