All The Examples of String to Enum Convertion taking only one String But In my Example String like this…
String allDays="MONDAY,SUNDAY,FRIDAY";
and My Enum Class like this..
public enum WeekdayType {
MONDAY(Calendar.MONDAY), TUESDAY(Calendar.TUESDAY), WEDNESDAY(
Calendar.WEDNESDAY), THURSDAY(Calendar.THURSDAY), FRIDAY(
Calendar.FRIDAY), SATURDAY(Calendar.SATURDAY), SUNDAY(
Calendar.SUNDAY);
private int day;
private WeekdayType(int day) {
this.day = day;
}
public int getDay() {
return day;
}
}
So in that Time WeedayType.valueOf(allDay) is giving error…..
Any suggestions for this..
You will be getting the below error
java.lang.IllegalArgumentException: No enum const class com.java.core.Test$WeekdayType.MONDAY,SUNDAY,FRIDAYThe reason is you are passing the following String to your WeedayType enum, which is an illegal argument as the exception says.
The valid values you can pass to valueOf method are “MONDAY”, “TUESDAY” etc.(i.e your enum names). Other values gives you java.lang.IllegalArgumentException which is the correct behaviour.