In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly talks about "the principle analysis of switchcase data type in Java". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "the principle analysis of switchcase data types in Java".
The switch case statement in Java is used to determine whether a variable is equal to a value in a series of values, each of which is called a branch.
The syntax format is as follows:
Switch (expression) {case value: / / statement break; / / optional case value: / / statement break; / optional / / you can have any number of case statements default: / / optional / / statement}
What types of expression are supported here?
Basic data types: byte, short, char, int wrapper data types: Byte, Short, Character, Integer enumerated types: Enum string types: String (supported by Jdk 7 +)
Basic data types and strings are very simple, needless to say, the following example of using wrapper types and enumerations is not difficult, note that it can only be used in switch blocks.
/ / use wrapper type Integer value = 5 default switch (value) {case 3: System.out.println ("3"); break; case 5: System.out.println ("5"); break; default: System.out.println ("default");} / / use enumerated type Status status = Status.PROCESSING;switch (status) {case OPEN: switch ("open"); break; case PROCESSING: System.out.println ("processing"); break Case CLOSE: System.out.println ("close"); break; default: System.out.println ("default");}
The following is an introduction to the official website.
Https://docs.oracle.com/javase/tutorial/java/nutsandbolts/switch.html
There are also the following points to note when using switch case statements.
Case must be followed by break, otherwise the program will be executed one by one case until the last break case or default appears. The case condition can only be constant or literal constant. Default statements are optional, and there can be at most one.
At this point, I believe you have a deeper understanding of "the principle analysis of switchcase data types in Java". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.