Tóm Tắt
Java Enum ordinal() Method
The 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.
Syntax
Return Value
The ordinal() method returns this enumeration constant’s ordinal.
Example 1
Output:
Red ordinal = 0 Green Ordinal = 1 Brown Ordinal = 2 Yellow Ordinal = 3
Example 2
Output:
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 3
Output:
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 Topic
Java Enum