Java learns java from scratch (enumeration definition and simple use), and Java starts from scratch
I. Enumeration
Enumeration refers to a type composed of a set of fixed constants, indicating a specific data set, but all possible values are known when this data set is defined.
We recommend that you use uppercase letters for the names of enumerated constants.
Enumerated constants are static enumerated fields, which are separated by commas.
Use the enum keyword to define an enumeration.
Package com. pb. demo1;/** days of one Week for Enumeration type */public enum Week {// MON, TUE, WED, THU, FRI, SAT, SUN} from Monday to Sunday}
Package com. pb. demo1; public class WeekDemoTest {/** indicates the day from Monday to Sunday for the input */public void doWhat (Week day) {switch (day) {case MON: System. out. println ("Monday, first day of work"); break; case TUE: System. out. println ("Tuesday, the second day"); break; case WED: System. out. println ("Wednesday, two other weekends"); break; case THU: System. out. println ("Thursday, another day"); break; case FRI: System. out. println ("Friday, today's weekend"); break; case SAT: System. out. printl N ("Saturday, resting, watching movies"); break; case SUN: System. out. println ("Sunday, rest, play"); break; default: System. out. println ("seven days a week on Earth! ") ;}} Public static void main (String [] args) {WeekDemoTest wdt = new WeekDemoTest (); // declare an enumeration type Week day = Week. THU; wdt. doWhat (day); // directly use wdt without declaring the enumeration type. doWhat (Week. TUE); System. out. println ("=========== traverse enumeration ============"); // traverse enumeration for (Week w: Week. values () {System. out. println (w );}}}