-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding Enum examples #61
Open
Tawishi
wants to merge
22
commits into
SiddharthaAnand:master
Choose a base branch
from
Tawishi:enum-java
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 15 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
2cd26d7
Create enum.java
Tawishi df6164a
Create enum_inside_class.java
Tawishi 35c8de7
Create enum_switch_case
Tawishi 0dc501c
Update enum_inside_class.java
Tawishi 89e89f4
Update enum.java
Tawishi a63e504
Create enum_.java
Tawishi e6105b3
Create enum_loop.java
Tawishi 3b62657
Rename enum_switch_case to enum_switch_case.java
Tawishi 3d9c37d
Rename enum.java to Day.java
Tawishi 0bd7bb4
Update enum_.java
Tawishi f62654a
Rename enum_.java to MyClass1.java
Tawishi 3804c8e
Adding updates
Tawishi 07768aa
Adding updates
Tawishi 634bfa0
Update and rename enum_switch_case.java to MyClass4.java
Tawishi 5243aa4
Create Readme.md
Tawishi 4a1ec04
Update and rename MyClass1.java to dotSyntax.java
Tawishi 0559f5a
Update and rename MyClass2.java to enumInsideClass.java
Tawishi b12c3f7
Update and rename MyClass3.java to enumLoop.java
Tawishi 4cadad9
Update and rename MyClass4.java to switchCase.java
Tawishi ba635ce
Create inBuiltFunc.java
Tawishi 2637a58
Update Readme.md
Tawishi 47de8e8
Correcting typo
Tawishi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
public enum Day { | ||
SUNDAY, MONDAY, TUESDAY, WEDNESDAY, | ||
THURSDAY, FRIDAY, SATURDAY | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
public class MyClass1 { | ||
Tawishi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
public static void main(String[] args) { | ||
Day variable = Day.TUESDAY | ||
System.out.println(variable); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
public class MyClass2 { | ||
Tawishi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
public static void main(String[] args) { | ||
Day myVar = Day.SUNDAY; | ||
System.out.println(myVar); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
public class MyClass3 { | ||
Tawishi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
public static void main(String[] args) { | ||
for (Day myVar : Day.values()) { | ||
System.out.println(myVar); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
public class MyClass4 { | ||
Tawishi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
public static void main(String[] args) { | ||
Day myVar = Day.WEDNESDAY; | ||
|
||
switch(myVar) { | ||
case MONDAY: | ||
System.out.println("Workday."); | ||
break; | ||
case TUESDAY: | ||
System.out.println("Presentaion day."); | ||
Tawishi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
break; | ||
case WEDNESDAY: | ||
System.out.println("Workday."); | ||
break; | ||
case THURSDAY: | ||
System.out.println("Workday."); | ||
break; | ||
case FRIDAY: | ||
System.out.println("PARTY!"); | ||
break; | ||
case SATURDAY: | ||
System.out.println("Relax."); | ||
break; | ||
case SUNDAY: | ||
System.out.println("Complete deadlines."); | ||
break; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move all the constants to a final variable and use it instead of hardcoding them in here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mean the statements I am displaying? |
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# About Repository | ||
This repository contains the *Enum class* in Java, with examples. Enum is short for "enumerations", which means "specifically listed".<br><br> | ||
An enum is a special "class" that represents a group of constants (unchangeable variables, like final variables). To create an enum, use the enum keyword (instead of class or interface), and separate the constants with a comma. *Note* that they should be in uppercase letters. | ||
|
||
## About files | ||
1. [Day.java][1] : Contains the enum class used in all other files (test class). | ||
1. [MyClass1.java][2] : Access enum constants with the dot syntax. | ||
1. [MyClass2.java][3] : Having enum inside another class. | ||
1. [MyClass3.java][4] : Returning an array of all enum constants using value() methis of enum type.This method is useful when you want to loop through the constants of an enum. | ||
1. [MyClass4.java][5] : Using enum in switch case statement | ||
|
||
[1]:https://github.com/Tawishi/datastructures/blob/enum-java/advanced_java/enum/Day.java | ||
[2]:https://github.com/Tawishi/datastructures/blob/enum-java/advanced_java/enum/MyClass1.java | ||
[3]:https://github.com/Tawishi/datastructures/blob/enum-java/advanced_java/enum/MyClass2.java | ||
[4]:https://github.com/Tawishi/datastructures/blob/enum-java/advanced_java/enum/MyClass3.java | ||
[5]:https://github.com/Tawishi/datastructures/blob/enum-java/advanced_java/enum/MyClass4.java |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use other Enum in built methods as well and show their functionality here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please name a few?