DayOfWeek valueOf() method in Java with Examples
The valueOf() method of java.time.DayOfWeek is an in-built function in Java which takes a string and returns an instance of DayOfWeek corresponding to the string. The string must match exactly to the identifier used to declare a day-of-week constant in this type. Extraneous white space characters are not permitted.
Method Declaration:
public static DayOfWeek valueOf(String name)
Syntax:
DayOfWeek dayOfWeekObject = DayOfWeek.valueOf(String name)
Parameters: This method takes name as parameter where:
Return Value: The function returns an instance of DayOfWeek corresponding to the name string
Below programs illustrate the above method:
Program 1:
// Java Program Demonstrate valueOf() // method of DayOfWeek import java.time.*; class DayOfWeekExample { public static void main(String[] args) { // Initializing a DayOfWeek instance DayOfWeek dayOfWeek = DayOfWeek.valueOf("MONDAY"); // Printing the day-of-week System.out.println(dayOfWeek.name()); } } |
MONDAY
Program 2:
// Java Program Demonstrate valueOf() // method of DayOfWeek import java.time.*; class DayOfWeekExample { public static void main(String[] args) { // Initializing a DayOfWeek instance DayOfWeek dayOfWeek = DayOfWeek.valueOf("SATURDAY"); // Printing the day-of-week System.out.println(dayOfWeek.name()); } } |
SATURDAY
Reference: https://docs.oracle.com/javase/8/docs/api/java/time/DayOfWeek.html#valueOf-java.lang.String-
Recommended Posts:
- DayOfWeek get() method in Java with Examples
- DayOfWeek plus() method in Java with Examples
- DayOfWeek from() method in Java with Examples
- DayOfWeek of() method in Java with Examples
- DayOfWeek values() method in Java with Examples
- DayOfWeek getValue() method in Java with Examples
- DayOfWeek minus() method in Java with Examples
- DayOfWeek getDisplayName() method in Java with Examples
- DayOfWeek adjustInto() method in Java with Examples
- TimeUnit valueOf() method in Java with Examples
- Locale.FilteringMode valueOf() method in Java with Examples
- Locale.Category valueOf() method in Java with Examples
- Java.lang.Long.valueOf() method with examples
- Character.valueOf() in Java with examples
- Integer valueOf() Method in Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


