To create an enumeration class
Packagecom.ywlaker.enums;/*** @ Function Description: Season enumeration class *@authorYang.wei * @time September 1, 2015 Morning 11:56:23 *@version0.0.1*/ Public enumSeason {SPRING ("Spring", "Spring"), SUMMER ("Summer", "Summer"), AUTUMN ("Autumn", "Autumn"), WINTER ("Winter", "Winter"); PrivateString Index; PrivateString name; PrivateSeason (string name, string index) { This. Name =name; This. index =index; } Public Staticstring GetName (string index) { for(Season s:season.values ()) {if(S.getindex (). Equals (index))returnS.getname (); } return NULL; } PublicString GetIndex () {returnindex; } Public voidsetindex (String index) { This. index =index; } PublicString GetName () {returnname; } Public voidsetName (String name) { This. Name =name; }}
Iterating through an enumeration class
Public Static string GetName (string index) { for (Season s:season.values ()) { if return s.getname (); } return NULL ; }
Basic usage of the enumeration class of Java