Content
1. What is Enum in Java?
2. Enum use in If Statement
3. Enum use in Switch Statement
4. Enum field
5. Enum method
6. Enum Iteration
1. What is enum?
An Enum in Java is:
- A special data type that enables for a variable to be a set of predefined constants.
- Its variable must be equal to one of the values that have been predefined for it.
- Enum able to contain field and method, etc and it was added in Java 5.
Example:
2. Enum use in If Statement
Developers like to enum to store constants variable for comparing by using If or Switch statement. So let's see enum as If Statement, we have Country enum that contains 3 fields:
If Statement:
3. Enum use in Switch Statement
Here is a sample, I had initialized it value "JAPAN". So our enum will run and check each value (PHNOM_PENH, JAPAN, KOREA). JAPAN's case will be true so it will set TextView to JAPAN on the screen.
4. Enum Field
We have 3 constructors that have each default value, if you use like this, it will return the default value, it has fruit field:
5. Enum Method
For enum method you can set/get the value from fruit fields like below:
6. Enum Iteration
You want to download this project from Github here! Thank You!
1. What is Enum in Java?
2. Enum use in If Statement
3. Enum use in Switch Statement
4. Enum field
5. Enum method
6. Enum Iteration
1. What is enum?
An Enum in Java is:
- A special data type that enables for a variable to be a set of predefined constants.
- Its variable must be equal to one of the values that have been predefined for it.
- Enum able to contain field and method, etc and it was added in Java 5.
Example:
2. Enum use in If Statement
Developers like to enum to store constants variable for comparing by using If or Switch statement. So let's see enum as If Statement, we have Country enum that contains 3 fields:
If Statement:
3. Enum use in Switch Statement
Here is a sample, I had initialized it value "JAPAN". So our enum will run and check each value (PHNOM_PENH, JAPAN, KOREA). JAPAN's case will be true so it will set TextView to JAPAN on the screen.
4. Enum Field
We have 3 constructors that have each default value, if you use like this, it will return the default value, it has fruit field:
Fruit.APPLE.getFruit()// LIKE Fruit.PINE_APPLE.getFruit()//DON'T LIKE Fruit.BANANA.getFruit()//NORMAL
5. Enum Method
For enum method you can set/get the value from fruit fields like below:
6. Enum Iteration
You want to download this project from Github here! Thank You!
This is an awesome post.Really very informative and creative contents.
ReplyDeleteIELTS Coaching in Chennai
Best IELTS Coaching in Chennai
French Language Classes in Chennai
pearson vue exam centers in chennai
Informatica MDM Training in Chennai
Hadoop Admin Training in Chennai
content writing course in chennai
IELTS Coaching in Tambaram
IELTS Coaching in Anna Nagar
I found that site very usefull and this survey is very cirious, I ' ve never seen a blog that demand a survey for this actions, very curious... Kopar at Newton Condo
ReplyDeleteThis is just the information I am finding everywhere. Thanks for your blog, I just subscribe your blog. This is a nice blog.. XE88
ReplyDeleteIt's late finding this act. At least, it's a thing to be familiar with that there are such events exist. I agree with your Blog and I will be back to inspect it more in the future so please keep up your act. TubeMate APK Review
ReplyDelete