Home >Java >javaTutorial >How to use ordinal in java
1. Concept
By calling ordinal() of the enumeration type, you can obtain the index position of the member in the enumeration.
2. Example
The following example creates an enumeration type Signal including 3 members, and calls the ordinal() method to output the members and corresponding index positions.
public enum Signal { //定义一个枚举类型 GREEN,YELLOW,RED; public static void main(String[] args) { Signal green = Signal.valueOf("GREEN"); System.out.println(green); } }
Collections in Java are mainly divided into four categories:
1. List: ordered, repeatable;
2. Queue: ordered and repeatable;
3. Set: non-repeatable;
4. Map: unordered, with unique keys and non-unique values.
The above is the detailed content of How to use ordinal in java. For more information, please follow other related articles on the PHP Chinese website!