Usage of Ordinal in Enum

Usage of Ordinal in Enum

The ordinal() method on the enum returns the constant. In other words, you can assume this to be the same as index and similar to arrays the index starts with zero(0).

Code snippet:

public class EnumOrdinal{   public static void main(String args[])   {      EnumOrdinal enumOrdinal = new EnumOrdinal();      enumOrdinal.proceed();   }      enum Days {      SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY;   }      private void proceed()   {      Days ordinalDay = Days.FRIDAY; //Change this value to one of the values in the enum Days to get the respective ordinal      System.out.println("Ordinal of " + ordinalDay + " is " + ordinalDay.ordinal());   }}/*Expected output: Ordinal of FRIDAY is 5*/
Share the Post:
data observability

Data Observability Explained

Data is the lifeblood of any successful business, as it is the driving force behind critical decision-making, insight generation, and strategic development. However, due to its intricate nature, ensuring the

Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular