DAY08----Enumeration In the Java language
First, overview:
What is an enumeration? What is the function of enumerations? How do we use this enumeration. In fact, the enumeration is immutable member variables, such as: Spring and Autumn, year, 12 months, color and so on. Are some fixed constant values. is used to create pre-defined lists. Enumerations are and classes are of a level. It can be defined directly as a class, or it can be defined in a class. You can also define methods, variables, constructors, and so on in the definition enumeration.
Second, enumeration:
Example one:
package www.com; //defines an enumeration. enum weekday{ monday,tuesday, wenesday,thursday,friday,saturday,sunday } public class enum { public static void main (String[] args)  {//1, accessed by enumeration name. System.out.println (Weekday.monday); System.out.println (weekday.tuesday);//2, accessed by applying variables. You can only use your own data type to accept it. Other types are not possible. weekday wd = weekday.sunday; SYSTEM.OUT.PRINTLN (wd);//3, outputs the ordinal of this enumeration System.out.println (Weekday.FRIDAY.ordinal ()),//4, iterates through the enumeration, is returned as an array, So use arrays to accept them. Weekday wdy[] = weekday.values ();for (Weekday weekday : wdy) { System.out.print (weekday+ ",");} } }
Third, concluding remarks:
We are done with our "enumeration" knowledge here. We know how to define an enumeration, how to use access to an enumeration, and how to iterate through an enumeration. You will also use it directly in the subsequent work. At least you have to be a stranger in the process of development.
This article from "Lonely One Night" blog, reproduced please contact the author!
----enumeration in the Java language