This is a follow up post to my other post about the Calendar Class ENUM DayOfWeek question.
***My question would be to ask for feedback from the moderators regarding the value of this class and method in creating calendar related applications***
This is new information and solves (for me) the purpose of outputting the TEXT form of the days of the week using the class DateFormatSymbols, and
the getWeekdays() method in addition to a for loop. Code example at the end of this post.
The thing to note is that the CONSTANT FIELD VALUES for the days of the week start with SUNDAY = 1 thru SATURDAY = 7. There is no 0th value.
The String array that holds the text version of the days of the week does have a 0th element, however, it is empty.
Thus, the for loop should start with -1- to begin with SUNDAY.
Here is the code per the link above:
Full name of day : Sunday
Full name of day : Monday
Full name of day : Tuesday
Full name of day : Wednesday
Full name of day : Thursday
Full name of day : Friday
Full name of day : Saturday
Roberta Fine wrote:Thus, the for loop should start with -1- to begin with SUNDAY.
Not necessarily. What about simply:
For me, this brings the process of using the Calendar and Date classes along with the related classes for formatting the output of the fields full circle.
I suspect it may have something to do with the flak they got for making Calendar.MONTH 0-based, which causes no end of mistakes. Far better, I reckon, to have a wasted array element than force everyone to use a convention they don't use anywhere else (although I'd also say that it's much less important with day numbers than it is with months).
Isn't it funny how there's always time and money enough to do it WRONG?
Artlicles by Winston can be found here
There have been a number of problems over the years using Calendar and Date. Hence, why developers look for other options like Joda Time and DateUtils. I would be surprised to find a junior Java developer that didn't fall into one of the many pitfalls with these classes.
Thank you for the feedback. I like the alternate loop method Winston, I'll keep that in my toolkit.
And James as for Joda-Time and DateUtils classes, I'll look into those next and see how they compare.
As it turns out, because of both the simplicity and complexity (including pitfalls) of these classes, I have learned a LOT about
abstraction, encapsulation, inheritance, getters and setters, and manipulating displays to be "human readable."
And, I'm thinking that's a good thing out here on the ranch....
Thank you again pardners!