enum ordinal

枚举类ordinal()方法 (Enum Class ordinal() method)

  • ordinal() method is available in java.lang package.

    ordinal()方法在java.lang包中可用。

  • ordinal() method is used to return the position of this enum constants is whatever defined in its enum declaration and the position of starting element of enum constant starts from 0.

    ordinal()方法用于返回此枚举常量的位置,无论其枚举声明中定义了什么,并且枚举常量的起始元素的位置均从0开始。

  • ordinal() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.

    ordinal()方法是一种非静态方法,只能通过类对象进行访问,如果尝试使用类名称访问该方法,则会收到错误消息。

  • ordinal() method is a final method, it does not override in child class.

    ordinal()方法是最终方法,它不会在子类中重写。

  • This method does not throw an exception at the time of returning the position of the enum constants.

    返回枚举常量的位置时,此方法不会引发异常。

Syntax:

句法:

    public final int ordinal();

Parameter(s):

参数:

  • It does not accept any parameter.

    它不接受任何参数。

Return value:

返回值:

The return type of this method is int, it returns the position of this enum constant.

该方法的返回类型为int ,它返回该枚举常量的位置。

Example:

例:

// Java program to demonstrate the example
// of int ordinal() of Enum class
enum Month {JAN,
FEB,
MAR,
APR,
MAY;
}
public class Ordinal {public static void main(String args[]) {Month m1 = Month.JAN;
Month m2 = Month.FEB;
Month m3 = Month.MAR;
Month m4 = Month.APR;
Month m5 = Month.MAY;
System.out.println("Display Ordinal: ");
// By using ordinal() method is to return the position of
//enum constant in its enum definition
System.out.println("m1.ordinal() " + " " + m1.ordinal());
System.out.println("m2.ordinal()" + " " + m2.ordinal());
System.out.println("m3.ordinal()" + " " + m3.ordinal());
System.out.println("m4.ordinal()" + " " + m4.ordinal());
System.out.println("m5.ordinal()" + " " + m5.ordinal());
}
}

Output

输出量

Display Ordinal:
m1.ordinal()  0
m2.ordinal() 1
m3.ordinal() 2
m4.ordinal() 3
m5.ordinal() 4

翻译自: https://www.includehelp.com/java/enum-ordinal-method-with-example.aspx

enum ordinal

enum ordinal_Java Enum ordinal()方法与示例相关推荐

  1. 0编译器详解_详解Java枚举类型(Enum)中的方法

    文章前记 程序员工作久了便可能整日忙碌于"增删改查"中,迷失方向,毫无进步. 该公众号致力于分享软件开发相关的原创干货,助你完成从程序员到架构师的进阶之路! 努力!做一个NB的Co ...

  2. Java 枚举(enum) 六种常用的方法详解

    JDK1.5引入了新的类型--枚举,在java中虽然枚举只是一个很小的功能,却给我们带来了很大的方便. 首先我们要了解几个概念,enum是没有构造函数的,准确的来说是没有public类型的构造函数, ...

  3. java 枚举 示例_Java枚举name()方法及示例

    java 枚举 示例 枚举类name()方法 (Enum Class name() method) name() method is available in java.lang package. n ...

  4. C语言 enum/typedef enum 枚举类型详解

    原文:http://z515256164.blog.163.com/blog/static/32443029201192182854300/ 在程序中,可能需要为某些整数定义一个别名,我们可以利用预处 ...

  5. typedef enum与enum的用法

    typedef enum {RESET = 0, SET = !RESET } FlagStatus, ITStatus; 这句话意思就是给enum {RESET = 0, SET = !RESET} ...

  6. enum和Enum类的区别,enum结构使用

    enum:从jdk1.5之后提供的一个关键字,用于定义枚举类: Enum:是一个抽象类,所有使用enum关键字定义的类默认继承了该类 package day09_Enum; /*** 定义枚举结构 * ...

  7. python clr createinstance_Python System.Byte方法代码示例

    本文整理汇总了Python中System.Byte方法的典型用法代码示例.如果您正苦于以下问题:Python System.Byte方法的具体用法?Python System.Byte怎么用?Pyth ...

  8. orm设置bool型 python_Python orm.relationship方法代码示例

    本文整理汇总了Python中sqlalchemy.orm.relationship方法的典型用法代码示例.如果您正苦于以下问题:Python orm.relationship方法的具体用法?Pytho ...

  9. python descript_Python descriptor.FieldDescriptor方法代码示例

    本文整理汇总了Python中google.protobuf.descriptor.FieldDescriptor方法的典型用法代码示例.如果您正苦于以下问题:Python descriptor.Fie ...

  10. 【POI操作word方法大全示例】

    POI操作word方法大全示例总结 提示:写完文章后,目录可以自动生成,如何生成可参考右边的帮助文档 文章目录 POI操作word方法大全示例总结 使用场景 一.poi是什么? 二.使用示例 1.代码 ...

最新文章

  1. 《OpenCV3编程入门》学习笔记5 Core组件进阶(三)分离合并颜色通道
  2. SQL Server中的高可用性----复制
  3. mysql 内存表使用教程_MySQL的内存表的基础学习教程
  4. (转)Cobbler无人值守批量安装Linux系统
  5. HP-JavaUtil: xls 操作类
  6. Python PyPI中国镜像
  7. 王思聪5亿投资神话破灭?旗下普思资本股权遭冻结,冻结期3年
  8. eclipse 使用maven 创建springmvc + mybatis
  9. oppo鸿蒙系统刷机包下载,OPPO A59st官方固件rom刷机包_OPPO A59st系统升级包下载
  10. Android SDK的环境变量配置
  11. 思科ASDM导入与实战配置经验总结-操作系统版本V842
  12. Java代码混淆技术选型
  13. vux移动端UI组件库
  14. 测试苹果手机主板软件,iphone手机硬件检测工具使用方法
  15. 实验六、contentprovider实验+SQLite数据库的实现
  16. dblink导致存储过程报异常ORA-03113:通信通道文件尾 ORA-02063紧接着line(xxxdblink名称) ORA-06512在(xxxx)line 24
  17. HDU 4489 找出n!个全排列数中的“波浪数” dp 思维,全排列
  18. ENVI:标准库中光谱(.sli)重采样
  19. 适用于Windows11 任务栏开始菜单和图标,资源管理器显示异常修复的方法
  20. 【ant-design】分页器英文如何转中文

热门文章

  1. Ubuntu文件系统损坏修复
  2. SOFTICE 初使用
  3. office 2016 官方完整版
  4. ClickHouse 函数极简教程
  5. 小米手机 root权限 获取
  6. Linux内核崩溃转存,Ubuntu 12.04 配置内核崩溃自动重启及转存
  7. 传统3D游戏引擎的Web化
  8. 2022-2027年中国图书馆RFID行业市场深度分析及投资战略规划报告
  9. 深入浅出计算机组成原理26-Superscalar和VLIW:如何让CPU的吞吐率超过1?
  10. android 5.0rom官方,Android 5.0刷机包开放下载 升级需谨慎