Saturday, July 4, 2026
HomeLanguagesJavaDayOfWeek values() method in Java with Examples

DayOfWeek values() method in Java with Examples

The values() method of java.time.DayOfWeek is an in-built function in Java which returns an array containing the days of the week, e.g. MONDAY, TUESDAY and so on, in the order they are declared.

Method Declaration:

public static DayOfWeek[] values()

Syntax:

DayOfWeek week[] =  DayOfWeek.values()

Parameters: This method does not accepts any parameters.

Return Value: The function returns an array containing the days of the week in the order they are declared.

Below programs illustrate the above method:
Program 1:




// Java Program Demonstrate values()
// method of DayOfWeek
import java.time.DayOfWeek;
  
class DayOfWeekExample {
    public static void main(String[] args)
    {
        // Initializing an array containing
        // all the days of the Week
        DayOfWeek week[] = DayOfWeek.values();
  
        // Printing the days of the Week
        for (DayOfWeek c : week)
            System.out.println(c);
    }
}


Output:

MONDAY
TUESDAY
WEDNESDAY
THURSDAY
FRIDAY
SATURDAY
SUNDAY

Program 2:




// Java Program Demonstrate values()
// method of DayOfWeek
import java.time.DayOfWeek;
  
class DayOfWeekExample {
    public static void main(String[] args)
    {
        // Initializing an array containing
        // all the days of the Week
        DayOfWeek week[] = DayOfWeek.values();
  
        // Printing the days of the Week
        for (int i = 0; i < week.length; i++)
            System.out.println(week[i]
                               + " has int value - "
                               + (i + 1));
    }
}


Output:

MONDAY has int value - 1
TUESDAY has int value - 2
WEDNESDAY has int value - 3
THURSDAY has int value - 4
FRIDAY has int value - 5
SATURDAY has int value - 6
SUNDAY has int value - 7

Reference: https://docs.oracle.com/javase/8/docs/api/java/time/DayOfWeek.html#values–

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

3 COMMENTS

Most Popular

Dominic
32519 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6900 POSTS0 COMMENTS
Nicole Veronica
12015 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12110 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6967 POSTS0 COMMENTS