Java programming: enumerate the days in a week.

Source: Internet
Author: User

Java programming: enumerate the days in a week.

Package enumeration; public class WeekDaysList {public static void main (String [] args) {// TODO Auto-generated method stubSystem. out. println ("Days of week:"); for (DaysOfTheWeek day: DaysOfTheWeek. the values () // values method returns an array containing an enumerated Constant list. System. out. printf ("% s", day); // The toString method will automatically call day. toString () is the same. system. out. println () ;}}// enumerate enum DaysOfTheWeek {MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, STAURDAY, SUNDAY; @ Overridepublic String toString () // override the parent class method. This method will automatically call {String s = super. toString (); // use toString to obtain the string representation of each constant. Return s. substring (0, 1) + s. substring (1). toLowerCase (); // keep the first letter of the string, and convert the remaining letters to lowercase letters .}}

Note: substring (0, 1) indicates that the first character is returned, that is, the value 0 does not include 1;

Substring (1) indicates that the index starts from the specified 1.EndIndex-1Character

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.