java.time.DayOfWeek的values()方法是Java中的內置函數,它返回包含星期幾的數組,例如星期一,星期二等,以它們聲明的順序。
方法聲明:
public static DayOfWeek[] values()
用法:
DayOfWeek week[] = DayOfWeek.values()
參數:此方法不接受任何參數。
返回值:該函數返回一個數組,該數組包含聲明星期幾的日期。
以下示例程序旨在說明上述方法:
示例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);
}
}
輸出:
MONDAY TUESDAY WEDNESDAY THURSDAY FRIDAY SATURDAY SUNDAY
示例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));
}
}
輸出:
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
參考: https://docs.oracle.com/javase/8/docs/api/java/time/DayOfWeek.html#values–
相關用法
- Java DayOfWeek plus()用法及代碼示例
- Java DayOfWeek of()用法及代碼示例
- Java DayOfWeek from()用法及代碼示例
- Java DayOfWeek get()用法及代碼示例
- Java DayOfWeek getValue()用法及代碼示例
- Java DayOfWeek valueOf()用法及代碼示例
- Java DayOfWeek adjustInto()用法及代碼示例
- Java DayOfWeek minus()用法及代碼示例
- Java WeekFields dayOfWeek()用法及代碼示例
- Java DayOfWeek getDisplayName()用法及代碼示例
- Java ChronoField values()用法及代碼示例
- Java AbstractMap values()用法及代碼示例
- Java TimeUnit values()用法及代碼示例
- Java TextStyle values()用法及代碼示例
- Java ChronoUnit values()用法及代碼示例
注:本文由純淨天空篩選整理自rupesh_rao大神的英文原創作品 DayOfWeek values() method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。