Enum Class DayOfWeek
- All Implemented Interfaces:
Serializable,Comparable<DayOfWeek>,java.lang.constant.Constable
DayOfWeek is an enum representing the 7 days of the week -
Sunday, Monday, Tuesday, Wednesday, Thursday, Friday and Saturday.
In addition to the textual enum name, each day-of-week has an int value.
The int value from 1 (Sunday) to 7 (Saturday).
It is recommended that applications use the enum rather than the int value
to ensure code clarity.
Do not use ordinal() to obtain the numeric representation of DayOfWeek.
Use getValue() instead.
This enum represents a common concept that is found in many calendar systems.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>> -
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionThe singleton instance for the day-of-week of Friday.The singleton instance for the day-of-week of Monday.The singleton instance for the day-of-week of Saturday.The singleton instance for the day-of-week of Sunday.The singleton instance for the day-of-week of Thursday.The singleton instance for the day-of-week of Tuesday.The singleton instance for the day-of-week of Wednesday. -
Method Summary
Modifier and TypeMethodDescriptionstatic DayOfWeekgetDayOfWeek(int value) Obtains an instance ofDayOfWeekfrom anintvalue.static DayOfWeekgetDayOfWeek(String name) Obtains an instance ofDayOfWeekfrom anStringvalue.getName()Gets the textual representation, such as 'Monday' or 'Friday'.Gets the textual representation, such as 'Mon' or 'Fri'.intgetValue()Gets the day-of-weekintvalue.minus(long days) returns the day-of-week that is the specified number of days before this oneplus(long days) Returns the day-of-week that is the specified number of days after this one.static DayOfWeekReturns the enum constant of this class with the specified name.static DayOfWeek[]values()Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
Sunday
The singleton instance for the day-of-week of Sunday. This has the numeric value of1. -
Monday
The singleton instance for the day-of-week of Monday. This has the numeric value of2. -
Tuesday
The singleton instance for the day-of-week of Tuesday. This has the numeric value of3. -
Wednesday
The singleton instance for the day-of-week of Wednesday. This has the numeric value of4. -
Thursday
The singleton instance for the day-of-week of Thursday. This has the numeric value of5. -
Friday
The singleton instance for the day-of-week of Friday. This has the numeric value of6. -
Saturday
The singleton instance for the day-of-week of Saturday. This has the numeric value of7.
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum class has no constant with the specified nameNullPointerException- if the argument is null
-
getValue
public int getValue()Gets the day-of-weekintvalue.The values are numbered from 1 (Sunday) to 7 (Saturday).
- Returns:
- the day-of-week, from 1 (Sunday) to 7 (Saturday)
-
getName
Gets the textual representation, such as 'Monday' or 'Friday'.This returns the textual name used to identify the day-of-week, suitable for presentation to the user.
- Returns:
- the text value of the day-of-week, not null
-
getShortName
Gets the textual representation, such as 'Mon' or 'Fri'.This returns the short textual name used to identify the day-of-week, suitable for presentation to the user.
- Returns:
- the short text value of the day-of-week, not null
-
minus
returns the day-of-week that is the specified number of days before this one- Parameters:
days-- Returns:
-
plus
Returns the day-of-week that is the specified number of days after this one.The calculation rolls around the end of the week from Saturday to Sunday. The specified period may be negative.
This instance is immutable and unaffected by this method call.
- Parameters:
days- the days to add, positive or negative- Returns:
- the resulting day-of-week, not null
-
getDayOfWeek
Obtains an instance ofDayOfWeekfrom anintvalue.DayOfWeekis an enum representing the 7 days of the week. This factory allows the enum to be obtained from theintvalue. Theintvalue from 1 (Sunday) to 7 (Saturday).- Parameters:
dayOfWeek- the day-of-week to represent, from 1 (Sunday) to 7 (Saturday)- Returns:
- the day-of-week singleton, or null if invalid value
-
getDayOfWeek
Obtains an instance ofDayOfWeekfrom anStringvalue.DayOfWeekis an enum representing the 7 days of the week. This factory allows the enum to be obtained from theStringvalue. TheStringvalue from "Sunday" or "Sun" (Sunday) to "Saturday" or "Sat" (Saturday).- Parameters:
dayOfWeek- the day-of-week to represent, from "Sunday" or "Sun" (Sunday) to "Saturday" or "Sat" (Saturday)- Returns:
- the day-of-week singleton, or null if invalid value
-