Java DayOfWeek enum

Java DayOfWeek is an enum representing the 7 days of the week.

Java DayOfWeek class methods

Method Description
int get(TemporalField field) It is used to get the value of the specified field from this day-of-week as an int.
boolean isSupported(TemporalField field) It is used to check if the specified field is supported.
DayOfWeek minus(long days) It is used to return the day-of-week that is the specified number of days before this one.
DayOfWeek plus(long days) It is used to return the day-of-week that is the specified number of days after this one.
static DayOfWeek of(int dayOfWeek) It is used to obtain an instance of DayOfWeek from an int value.
static DayOfWeek[] values() It is used to return an array containing the constants of this enum type, in the order they are declared.

Example

package com.w3schools;
 
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.Month;
import java.time.temporal.ChronoField;
 
public class TestExample {
	public static void main(String args[]){
	    LocalDate localDate = LocalDate.of(2018, Month.APRIL, 15);  
	    DayOfWeek dayOfWeek = DayOfWeek.from(localDate);  
	    System.out.println(dayOfWeek.get(ChronoField.DAY_OF_WEEK)); 
 
	    //of() method
	    DayOfWeek day = DayOfWeek.of(2);  
	    System.out.println(day.name());  
	    System.out.println(day.ordinal());  
	    System.out.println(day.getValue());
	}  
}

Output

7
TUESDAY
1
2