For names not related to the English day of the week, see Reply from tete .
TL; DR
DayOfWeek.valueOf( "Monday".toUppercase() ) // `DayOfWeek` object. Works only for English language. .getValue() // 1
java.time
If the names of your day of the week are a full-sized name in English (Monday, Tuesday, etc.), this matches the names of the enumeration objects defined in DayOfWeek enum.
Convert your entries to all uppercase letters and analyze to get a permanent object for that day of the week.
String input = "Monday" ; String inputUppercase = input.toUppercase() ;
Now that we have a fully functional object, not a string, ask for the integer of this day of the week, where Monday is 1 and Sunday is 7 (standard ISO 8601 ).
int dayOfWeekNumber = dow.getValue() ;
Use DayOfWeek objects, not strings
I urge you to minimize the use of either the name or the number of days of the week. Instead, use DayOfWeek objects whenever possible.
By the way, you can localize the name of the day of the week automatically.
String output = DayOfWeek.MONDAY.getDisplayName( TextStyle.FULL , Locale.CANADA_FRENCH );
This localization is one-way only through the DayOfWeek class. To go in a different direction in languages other than English, see Answer tet .
About java.time
The java.time framework is built into Java 8 and later. These classes supersede the nasty old legacy time classes such as java.util.Date , Calendar and SimpleDateFormat .
The Joda-Time project, now in maintenance mode , we recommend switching to the java.time classes.
To learn more, see the Oracle Tutorial . And search for qaru for many examples and explanations. JSR 310 specification .
Where to get java.time classes?
- Java SE 8 and SE 9 and later
- Built in.
- Part of the standard Java API with integrated implementation.
- Java 9 adds some minor features and fixes.
- Java SE 6 and SE 7
- Most of the functionality of java.time has been ported to Java 6 and 7 in ThreeTen-Backport .
- Android
- The ThreeTenABP project adapts ThreeTen-Backport (mentioned above) specifically for Android.
- See How to use ThreeTenABP ....
The ThreeTen-Extra project extends java.time with additional classes. This project is a proof of possible future additions to java.time. Here you can find useful classes such as Interval , YearWeek , YearQuarter and more .