Home  >  Article  >  Java  >  How to use ordinal in java

How to use ordinal in java

WBOY
WBOYforward
2023-05-28 09:01:191319browse

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);
        }
 
}

What collection classes are there in Java?

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!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete