Java Enum enumeration using the example

Source: Internet
Author: User

 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.