In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains the use of "java enumeration enum". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn the usage of java enumeration enum.
1. Construction method
Proprietary construction method
two。 Inheritance relationship
Inherit Enum by default
3. Main methods
Name: the name of the enumerated object
Ordinal: enumerates the order of objects in the class (index)
Values: gets all enumerated objects (returns an array of values)
CompareTo: object comparison
ValueOf: getting enumerated objects
4. Two ways of writing
a. Attribute-free method
Public enum TestEnum {MONDAY,TUESDAY,WEDNESDAY,THURSDAY, FRIDAY,SATURDAY,SUNDAY}
b. Method with attributes
Public enum TestEnum {/ / if you have your own properties, you need to give a construct with parameters, and you need to add corresponding values to the enumeration properties, that is, name MONDAY ("Monday"), TUESDAY ("Tuesday"), WEDNESDAY ("Wednesday"), THURSDAY ("Thursday"), FRIDAY ("Friday"), SATURDAY ("Saturday"), SUNDAY ("Sunday"); / / the semicolon must be added with private String name TestEnum (String name) {this.name = name;} public String getName () {return name;} public void setName (String name) {this.name = name;}}
5. Application
Public static void method () {TestEnum [] testEnums = TestEnum.values (); for (TestEnum t: testEnums) {String name = t.getName (); switch (name) {case "Monday": System.out.println (Monday); break Case "Tuesday": System.out.println ("Tuesday"); break; case "Wednesday": System.out.println ("Wednesday"); break Case "Thursday": System.out.println ("Thursday"); break; case "Friday": System.out.println ("Friday"); break Case "Saturday": System.out.println ("Saturday"); break; case "Sunday": System.out.println ("Sunday"); break Thank you for your reading, the above is the content of "java enumerating the usage of enum". After the study of this article, I believe you have a deeper understanding of the use of java enumerating enum, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.