TL; DR
LocalDate.now( ZoneId.of( "Pacific/Auckland" ) ) .plusDays( 5 ) .getDayOfWeek() .getDisplayName( TextStyle.FULL , Locale.US )
More details
Take a break from the idea of an array index related to the day of the week.
In addition, it is usually better to use a modern collection object to collect your objects, rather than a simple array.
Also avoid the problematic Calendar class. Now java.time classes are being superseded .
First get the current date. The LocalDate class represents a date value only without time and without a time zone.
The time zone is critical for determining the date. At any given moment, the date changes around the world by zone. For example, a few minutes after midnight in Paris, France is a new day, still "yesterday" in Montreal Quebec .
Specify the name of the current time zone in continent/region format, such as America/Montreal , Africa/Casablanca or Pacific/Auckland . Never use an abbreviation of 3-4 characters, such as EST or IST , as they are not real time zones, and are not standardized or even unique (!).
ZoneId z = ZoneId.of( "America/Montreal" ); LocalDate today = LocalDate.now( z );
We know that yesterday’s result is yesterday , so there’s no need to calculate this date. If you need a date, call LocalDate::minusDays .
We can set each LocalDate for the name of our day by retrieving the DayOfWeek enumeration object. It is DayOfWeek to know your own name in any human language that you can specify through the Locale object. Therefore, you do not need to track an array of string name names. Tip. In OOP, try to think either (a) to let the objects be smart, take care of yourself, or (b) enlist the help of an auxiliary object, rather than using the main arrays to do all the work yourself.
List<String> dayNames = new ArrayList<>( 7 ) ; // Initialize to seven days of a week. dayNames.add( "yesterday" ) ; dayNames.add( "today" ) ; for( int i = 1 ; i <= 5 ; i ++ ) { LocalDate ld = today.plusDays( i ) ; String dayName = ld.getDayOfWeek().getDisplayName( TextStyle.FULL , Locale.US ) ; dayNames.add( dayName ) ; // Add each of the five days remaining in a week. }
Try code live in IdeOne.com .
[yesterday, today, tuesday, wednesday, thursday, friday, saturday]
About java.time
The java.time framework is built into Java 8 and later. These classes supersede the nasty old legacy datetime classes such as java.util.Date , Calendar and SimpleDateFormat .
The Joda-Time project, now in maintenance mode , is advised to switch to the java.time classes.
To learn more, see the Oracle Tutorial . And search for qaru for many examples and explanations. JSR 310 specification .
Where to get java.time classes?
The ThreeTen-Extra project extends java.time with additional classes. This project is proof of possible future additions to java.time. Here you can find useful classes such as Interval , YearWeek , YearQuarter and more .