PackageCn.edu.shu.web.util;/** * * <p> * ClassName FileType * </p> * <p> * Description A small example to illustrate the use of enum, today, a special setback, is ctrl+shift+ O Cannot delete unused packages,<br/> * has been no problem, how to try today, and finally found that the problem of Sogou input method, after switching off the input method, shortcut keys can be used * </p> * * @author Tkpad [ Email protected] * <p> * Date March 13, 2015 PM 1:07:39 * </p> * @version V1.0.0 * */ Public enumFileType {WORD (1), TXT (2), ANNO (3);//Note that the sentence must be placed in the first line Private intType//define the variable used in the database, or the value of the enumeration variable //Use a constructor to assign a value to a defined enumeration variable Private FileType(intType) { This. type = type; }//By overwrite the ToString method, you can get the value of the enumeration variable @Override PublicStringtoString() {returnString.valueof ( This. type); }}
Package CN. edu. Shu. Web. Test;Import Java. Util. Enummap;Import CN. edu. Shu. Web. Util. FileType;public class Testenum {public static void main (string[] args) {//Traversal value of enum type filetype[] values = FileType. Values();for (FileType filetype:values) {System. out. println("Name:"+ FileType. Name());System. out. println("Ordinal:"+ FileType. Ordinal());System. out. println("Value:"+ FileType);}//Using Enummap enummap<filetype, string> enumm = new Enummap<filetype, string> (FileType. Class);Enumm. Put(FileType. WORD,"Word file");Enumm. Put(FileType. TXT,"text File");Enumm. Put(FileType. ANNO,"Callout File");Traverse object for (FileType Filetype:filetype. Values()) {System. out. println(Enumm. Get(FileType));} }}
Java Enum enumeration using the example