First, enumerate
Enumerations are types that consist of a fixed set of constants that represent a specific set of data, except that all possible values are known when the data collection is defined.
The name of the enumeration constant is proposed in uppercase.
Enumeration constants are static fields of enumerations, and enumeration constants are separated by commas.
Use a keyword enum to define an enumeration
Package Com.pb.demo1; /* */publicenum Week {// Monday to Sunday MON, Tue,wed,thu,fri,sat,sun}
PackageCom.pb.demo1; Public classWeekdemotest {/** from Monday to Sunday what day do you fix?*/ Public voiddowhat (Week day) {Switch(day) { CaseMON:System.out.println ("Monday, first day of work"); Break; CaseTUE:System.out.println ("Tuesday, the second day of the bitter force."); Break; CaseWED:System.out.println ("Wednesday, there are two genius weekends."); Break; CaseTHU:System.out.println ("Thursday, come on, there's a day."); Break; CaseFRI:System.out.println ("Friday, after today's weekend."); Break; CaseSAT:System.out.println ("Saturday, rest, see the movie"); Break; CaseSUN:System.out.println ("Sunday, rest and play"); Break; default: System.out.println ("7 days a week on earth!" "); } } Public Static voidMain (string[] args) {weekdemotest WDT=Newweekdemotest (); //declaring an enumeration typeWeek Day =Week.thu; Wdt.dowhat (day); //Direct use without declaring enum type directlyWdt.dowhat (Week.tue); System.out.println ("========= Traversal enumeration ==========="); //Traversal Enumeration for(Week w:week.values ()) {System.out.println (w); } }}
Java starts from zero 25 (enumeration definition and simple use)