java 枚举 示例

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

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

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

  • name() method is used to return the name of this enum constants as it is declared in its enum prototype or declaration.

    name()方法用于返回此枚举常量的名称,该名称在其枚举原型或声明中进行了声明。

  • name() 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.

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

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

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

  • name() method does not throw an exception at the time of returning the name of the enum constants.

    返回枚举常量名称时, name()方法不会引发异常。

Syntax:

句法:

    public final String name();

Parameter(s):

参数:

  • It does not accept any parameter.

    它不接受任何参数。

Return value:

返回值:

The return type of this method is String, it returns the name of this enum constant.

该方法的返回类型为String ,它返回此枚举常量的名称。

Example:

例:

// Java program to demonstrate the example
// of String name() of Enum method
enum Month {JAN,
FEB,
MAR,
APR,
MAY;
}
public class Name {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 Name: ");
// By using name() method is to get the enum
// constant name
System.out.println("m1.name() " + " " + m1.name());
System.out.println("m2.name()" + " " + m2.name());
System.out.println("m3.name()" + " " + m3.name());
System.out.println("m4.name()" + " " + m4.name());
System.out.println("m5.name()" + " " + m5.name());
}
}

Output

输出量

Display Name:
m1.name()  JAN
m2.name() FEB
m3.name() MAR
m4.name() APR
m5.name() MAY

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

java 枚举 示例

java 枚举 示例_Java枚举name()方法及示例相关推荐

  1. java secretkey用法_Java SecretKeyFactory.generateSecret方法代码示例

    本文整理汇总了Java中javax.crypto.SecretKeyFactory.generateSecret方法的典型用法代码示例.如果您正苦于以下问题:Java SecretKeyFactory ...

  2. java currency 默认_Java Currency getDefaultFractionDigits()方法与示例

    Currency类getDefaultFractionDigits()法getDefaultFractionDigits()方法在java.util包中可用. getDefaultFractionDi ...

  3. java currency 默认_Java Currency getCurrencyCode()方法与示例

    Currency类getCurrencyCode()法getCurrencyCode()方法在java.util包中可用. getCurrencyCode()方法用于获取此Currency的ISO 4 ...

  4. java input.close()_Java InputStream close()方法与示例

    InputStream类close()方法close()方法在java.io包中可用. close()方法用于关闭此InputStream并释放与此流链接的所有系统资源. close()方法是一种非静 ...

  5. java metadata 使用_Java DatabaseMetaData getColumns()方法与示例

    此方法检索表的列的描述.它接受4个参数-catalog-目录-一个字符串参数,表示表(包含通常需要检索其描述的列的表)的目录(通常是数据库)的名称(或名称模式).传递""以获取没有 ...

  6. java metadata 使用_Java DatabaseMetaData getTables()方法与示例

    此方法检索指定数据库/目录中可用表的描述.它接受4个参数-catalog-字符串参数,代表表(通常是数据库)的名称(或名称模式),表(其中包含您需要检索其描述的列)存在于其中.传递"&quo ...

  7. java formatter 填充_Java Formatter format()方法及示例

    格式化程序类format()方法 语法:public Formatter format(Locale lo, String frmt, Object... args); public Formatte ...

  8. Java图片扫描仪_Java扫描仪useDelimiter()方法及示例

    扫描仪类useDelimiter()方法 语法:public Scanner skip(Pattern patt); public Scanner skip(String patt);useDelim ...

  9. java polygon 用法_Java Polygon.getBounds方法代码示例

    import java.awt.Polygon; //导入方法依赖的package包/类 private SelectionShape translatePointsToRealSize(Select ...

  10. java makedir用法_Java Files.makeDir方法代码示例

    import org.nutz.lang.Files; //导入方法依赖的package包/类 protected void download(String openid, String media_ ...

最新文章

  1. 吴渴楨 160809206
  2. 转】R利剑NoSQL系列文章 之 Hive
  3. 基于 Java NIO 实现简单的 HTTP 服务器
  4. js中split字符串分割示例
  5. VTK:图片之ImageNonMaximumSuppression
  6. 鸿蒙系统无限延期,鸿蒙系统下月到来,三款手机首批升级,华为P50系列延期发布!...
  7. oracle 的变量的定义和赋值
  8. docker 容器的常用命令及配置
  9. 期望为线性的选择算法
  10. 新浪微盘等大批网盘将关停 你的私藏文件导出来了吗?
  11. openEuler软件包加固项目笔记
  12. TensorFlow学习笔记之 PReLU激活函数原理和代码
  13. 方正快速开发平台ES2007数据导入功能问题总结
  14. android 打开短信应用,通过短信打开手机应用
  15. 小学计算机社团活动总结,小学科技社团活动总结
  16. 鉴客 iPad横屏(Landscape)尺寸规格说明
  17. excel如何输入公式的技巧
  18. Linux下网络传输测速程序小记
  19. Excel转储mysql_小程序解析excel表格并存储到云数据库
  20. win10+vs2017配置mpi环境的记录(已成功)

热门文章

  1. uint8 转换为 float
  2. mysql 快速插入(insert)多条记录
  3. go反射机制与类型识别
  4. Problem D: 链表的基本运算(线性表)
  5. ELK 日志处理开发指南
  6. ajax+lazyload时lazyload失效问题及解决
  7. 如何安装Genymotion虚拟机以及Genmotion的eclipse插件
  8. HTML5——section,article,aside
  9. Microsoft Dynamics CRM 数据库连接存储位置在哪里 是在注册表里
  10. Datagridview拖放数据到TreeView