Java Enum ordinal() MethodThe ordinal() method of Enum class returns the ordinal of this enumeration constant. This method is designed to be used by sophisticated enum-based data structures, like EnumSet and EnumMap. SyntaxReturn ValueThe ordinal() method returns this enumeration constant's ordinal. Example 1Test it NowOutput: Red ordinal = 0 Green Ordinal = 1 Brown Ordinal = 2 Yellow Ordinal = 3 Example 2Test it NowOutput: First name = Reema Last name = Panda Position in class = 1 First name = Himanshu Last name = Bhardwaj Position in class = 2 First name = Geetanjali Last name = Sharma Position in class = 3 Example 3Test it NowOutput: Movies of Shahrukh Khan: 0 Don 1 DDlJ 2 Fan 3 Zero 4 VeerZara Q In which movie Shah rukh khan has played a dual role ? Ans. 3 Zero Sorry!You Failed. The Correct answer is Don.
Next TopicJava Enum
|