125. Java enumeration (enum)

Java enumeration (enum)

Java enumeration is a special class that generally represents a set of constants, such as 4 seasons of a year, 12 months of a year, 7 days of a week, etc.

The enumeration class defined by enum inherits the java.lang.Enum class by default, and implements the two interfaces java.lang.Seriablizable and java.lang.Comparable.

The values(), ordinal() and valueOf() methods are located in the java.lang.Enum class:

  •  

  • values() returns all the values ​​in the enumeration class.

  •  

  • The ordinal() method can find the index of each enum constant, just like an array index.

  •  

  • The valueOf() method returns the enum constant of the specified string value.

  •  

Guess you like

Origin blog.csdn.net/weixin_43206161/article/details/113001745