---
title: "Enumeration in Java"  
description: "Hi everyone in this article I am telling you how to use enum in Java"  
author: "Manoj Pandey"  
published: 2015-04-14  
updated: 2017-12-05  
canonical: https://www.mindstick.com/articles/1722/enumeration-in-java  
category: "java"  
tags: ["java"]  
reading_time: 2 minutes  

---

# Enumeration in Java

In java have an enum [keyword](https://yourviews.mindstick.com/view/87345/explained-the-importance-of-keyword-traffic) which represents a special data type that enables for a [variable](https://www.mindstick.com/blog/11493/what-is-a-variable) to belong to a set of predefined constants. The variable must be equal to one of the [values](https://www.mindstick.com/forum/159360/how-to-write-sql-query-to-join-comma-separated-values) that have been predefined for it. An enum type is a special data type that enables for a variable to be a set of predefined constants.\

The [Enumeration](https://www.mindstick.com/blog/88/enumeration-in-c-sharp) [interface](https://www.mindstick.com/articles/12036/interface-in-c-sharp) defines the [methods](https://www.mindstick.com/articles/13060/runny-nose-remedy-methods-that-work-best) by which you can enumerate (obtain one at a time) the [elements](https://www.mindstick.com/forum/1440/wpf-button-with-multiple-text-elements) in a [collection](https://www.mindstick.com/articles/1718/collections-in-java) of objects.

##### Advantages of Enum-:

##### \
· Enum improves type safety

##### \
· Enum can be easily used in switch

##### \
· Enum can be traversed

##### \
· Enum can have fields, constructors and methods.

##### \
· Enum may implement many interfaces but cannot extend any class because

##### it internally extends Enum class

Here I am creating a [sample](https://answers.mindstick.com/qa/43867/where-can-i-get-sample-or-past-question-papers-for-jamia-milia-islamia-entrance-exam-for-master-in-travel-tourism-management) of Enum which help you to clear the [concepts](https://www.mindstick.com/articles/13127/macro-and-microeconomics-concepts-in-relation-to-global-organization-management) of Enumeration in java.

```
public class Sample {      public static void main(String args[]) {            EnumExample days = new EnumExample(Day.MONDAY);           days = new EnumExample(Day.TUESDAY);           days = new EnumExample(Day.WEDNESDAY);           days = new EnumExample(Day.THURSDAY);           days = new EnumExample(Day.FRIDAY);           days = new EnumExample(Day.SATURDAY);           days = new EnumExample(Day.SUNDAY);      }} enum Day {     SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY} class EnumExample {     Day day;      public EnumExample(Day day) {           this.day = day;           tellItLikeItIs();      }      public void tellItLikeItIs() {           switch (day) {           case MONDAY:         System.out.println("Mondays is first day of the week");                 break;           case TUESDAY:         System.out.println("Tuesday is the second day of the week");                 break;           case WEDNESDAY:         System.out.println("Wednesday is the third day of the week");                break;           case THURSDAY:         System.out.println("Thursday is the fourth day of the week");                break;            case FRIDAY:         System.out.println("Friday is the fifth day of the week");                break;           case SATURDAY:         System.out.println("Saturday is the sixth day of the week");                break;           case SUNDAY:         System.out.println("Sunday is the Last day of the Week");                break;            default:                System.out.println("None of day");                break;           }     }} 
```

##### Output-:

```
Mondays is first day of the weekTuesday is the second day of the weekWednesday is the third day of the weekThursday is the fourth day of the weekFriday is the fifth day of the weekSaturday is the sixth day of the weekSunday is the Last day of the Week
```

---

Original Source: https://www.mindstick.com/articles/1722/enumeration-in-java

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
