Getting all the values of Enum by values()

Hi Friends,

For Enum refer previous post – clickhere

Now we are discussing how to access all the values of Enum with values().

Suppose we have created Course Enum.

So, we can specify values of enum constants at the creation time. Course.values() returns an array of Course’s values.

Following is demo code…

enum Course{
DONTNET,JAVA,PHP,ANDROID,CCNA;public String yourCourse(Course c){
return “Your Course is ” + c;
}

public static void main(String[] args) {
for (Course c : Course.values()) {

System.out.println(c.yourCourse(c));
}
}

}
class DemoClass{
public static void main(String[] args) {
for (Course c : Course.values()) {
System.out.println(c.yourCourse(c));
}
}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s