Home> Java> javaTutorial> body text

How to use ordinal in java

WBOY
Release: 2023-05-28 09:01:19
forward
1104 people have browsed it

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); } }
Copy after login

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!