Skip to content

Instantly share code, notes, and snippets.

@prisoner
Created July 29, 2011 07:58
Show Gist options
  • Save prisoner/1113411 to your computer and use it in GitHub Desktop.
Save prisoner/1113411 to your computer and use it in GitHub Desktop.
Strings in switch Statements
public String getTypeOfDayWithSwitchStatement(String dayOfWeekArg) {
String typeOfDay;
switch (dayOfWeekArg) {
case "Monday":
typeOfDay = "Start of work week";
break;
case "Tuesday":
case "Wednesday":
case "Thursday":
typeOfDay = "Midweek";
break;
case "Friday":
typeOfDay = "End of work week";
break;
case "Saturday":
case "Sunday":
typeOfDay = "Weekend";
break;
default:
throw new IllegalArgumentException("Invalid day of the week: " + dayOfWeekArg);
}
return typeOfDay;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment