Don't talk about anything. paste the Code directly ~ Record it for future use. Run the TestEnum class to view the effect ~ 1. enum Color [java]/*****/package hpf. test; import java. util. enumMap; import java. util. enumSet;/*** Enum class Color * @ author pengfei. hpf **/public enum Color implements ColorInterface {/*** Enumeration type definition, corresponds to the constructor */RED ("RED", 1), GREEN ("GREEN ", 2), BLANK ("white", 3), YELLOW ("YELLOW", 4); private String name; private int index; /** constructor * @ param name * @ param index */private Color (String name, int index) {this. name = name; this. index = index;}/* (non-Javadoc) * @ see hpf. test. colorInterface # getName () */@ Override public String getName () {return this. name;}/* (non-Javadoc) * @ see hpf. test. colorInterface # print () */@ Override public String print () {String msg = "index:" + index + "name:" + name; System. out. println (msg); return msg;} public static final EnumSet <Color> enumSet = EnumSet. allOf (Color. class); public static final EnumMap <Color, String> enumMap = new EnumMap <Color, String> (Color. class);} 2. interface Class [java]/*****/package hpf. test;/*** interface class * @ author pengfei. hpf **/public interface ColorInterface {/** get the name of the Color of the name Enumeration type * @ return */public String getName (); /** print information of the enumeration type * @ return */public String print ();} 3. test class [java] <pre name = "code" class = "java"> package hpf. test; import java. util. iterator;/** example of using the Enum class * @ author pengfei. hpf **/public class TestEnum {public static final int RED = 1; public static final int GREEN = 2; /*** @ param args */public static void main (String [] args) {enumFunc (); enumSetFunc (); enumMapFunc ();} /*** test the basic method */public static void enumFunc () {System. out. println ("enumFunc:" + Color. RED. getName (); Color. YELLOW. print ();}/*** all Enum objects in EnumSet are unique */public static void enumSetFunc () {Iterator <Color> it = Color. enumSet. iterator (); while (it. hasNext () {Color c = (Color) it. next (); c. print ();} System. out. println ("enumSet:" + Color. enumSet. toString ();}/*** enumMap test method. The key must be Enum-type data, and the value can be of any type */public static void enumMapFunc () {Color. enumMap. put (Color. RED, "This is RED"); Color. enumMap. put (Color. GREEN, "I am RED"); Color. enumMap. put (Color. YELLOW, "Oh, you are too yellow"); for (Color color: Color. enumMap. keySet () {System. out. println ("enumMap:" + Color. enumMap. get (color) ;}}</pre> [java]