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

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 枚举 示例

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/543975.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

SpringBoot 解决跨域问题的 5 种方案!

作者 | 磊哥来源 | Java面试真题解析(ID:aimianshi666)转载请联系授权(微信ID:GG_Stone)跨域问题指的是不同站点之间,使用 ajax 无法相互调用的问题。跨域问题本质是浏览器的一种保护机制&#…

Java 中的 Lombok 到底能不能用?

一、摘要Java,作为一款非常热门的编程语言,尽管它有着非常丰富的语言特性,完全面向对象编程,编程高度规范化,但是也有一个最受大家诟病的一个缺点:啰嗦,尤其是当你开发了很多年之后,…

旅行商问题

旅行商问题 (Travelling Salesman problem) This problem can be stated as- "Given n number of cities and a travelling salesman has to visit each city. Then we have to find the shortest tour so that the travelling salesman can visit each and every city on…

清除元素中的子元素html_HTML中的元素简介

清除元素中的子元素htmlAn element is a fundamental component that is used to develop web pages. Generally an element as two components: a starting tag and a closing tag. The content is added in between the starting and closing tags. The ending tag is the sa…

分页 + 模糊查询竟然有坑?

不知道你有没有使用过Mysql的like语句,进行模糊查询?不知道你有没有将查询结果,进行分页处理?模糊查询,加上分页处理,会有意想不到的坑,不信我们继续往下看。我之前提供过一个品牌查询接口&…

导致事务@Transactional失效的5种场景!

作者 | 磊哥来源 | Java面试真题解析(ID:aimianshi666)转载请联系授权(微信ID:GG_Stone)一个程序中不可能没有事务,而 Spring 中,事务的实现方式分为两种:编程式事务和声…

操作系统 cpu调度_CPU调度| 操作系统

操作系统 cpu调度调度标准 (Scheduling Criteria) There are many criteria which have been suggested for comparing the CPU scheduling algorithms. The characteristics which are used for comparison and then used to determine the best algorithms, for this some of…

IOS中KVO模式的解析与应用

最近老翁在项目中多处用到了KVO,深感这种模式的好处。现总结如下: 一、概述 KVO,即:Key-Value Observing,它提供一种机制,当指定的对象的属性被修改后,则对象就会接受到通知。简单的说就是每次指定的被观察…

使用 lambda 实现超强的排序功能

我们在系统开发过程中,对数据排序是很常见的场景。一般来说,我们可以采用两种方式:借助存储系统(SQL、NoSQL、NewSQL 都支持)的排序功能,查询的结果即是排好序的结果查询结果为无序数据,在内存中…

java 的23种设计模式 之单身狗和隔壁老王的故事

2019独角兽企业重金招聘Python工程师标准>>> 觉得代码写的别扭了,回头翻翻java 的23种设计模式。today,额,这么晚了,困了。就弄个最简单的单例模式吧。单例模式:俗称单身狗 package singleton; public class SingleTon { private …

使用python学线性代数_二项式过程| 使用Python的线性代数

使用python学线性代数When we flip a coin, there are two possible outcomes as head or tail. Each outcome has a fixed probability of occurrence. In the case of fair coins, heads and tails each have the same probability of 1/2. In addition, there are cases in …

工作中常见的 6 种设计模式,你用过几种?

前言 哈喽,大家好。平时我们写代码呢,多数情况都是流水线式写代码,基本就可以实现业务逻辑了。如何在写代码中找到乐趣呢,我觉得,最好的方式就是:使用设计模式优化自己的业务代码。今天跟大家聊聊日常工作中…

c#抽象属性_C#中的抽象属性

c#抽象属性C#抽象属性 (C# Abstract properties) An abstract may contain some abstract properties. That can be implemented in derived class. Here we use abstract and override keywords. 抽象可能包含一些抽象属性。 可以在派生类中实现 。 在这里&#xf…

这12款idea插件,能让你代码飞起来!

前言基本上每个程序员都会写代码,但写代码的速度不尽相同。为什么有些人,一天只能写几百行代码?而有些人,一天可以写几千行代码?有没有办法,可以提升开发效率,在相同的时间内,写出更…

node js 开发网站_使用Node JS开发网站

node js 开发网站You will have your own fully functional website running on "localhost" after going through this article. 阅读完本文后,您将在“ localhost”上运行自己的功能齐全的网站 。 Basic knowledge of JavaScript and HTML is a prereq…

hdu 1166 敌兵布阵

Problem DescriptionC国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了。A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视这些工兵营地的活动情况。由于采取了某种先进的监测手段,所以每个工兵营地…

Java:LocalDate / LocalDateTime加减时间

在线API参考:LocalTime (Java Platform SE 8 ) 方法介绍 方法1方法1说明plusYears(long years) minusYears(long years) 返回增加/减少了年数的副本plusMonths(long months) minusMonths(long months)返回增加/减少了月数的副本plusWeeks(long weeks) minusWeeks(…

集合 List 分片的 5 种实现

作者 | 磊哥来源 | Java中文社群(ID:javacn666)转载请联系授权(微信ID:GG_Stone)前些天在实现 MyBatis 批量插入时遇到了一个问题,当批量插入的数据量比较大时,会导致程序执行报错&a…

消失的死锁

问题描述 如果java层面发生了死锁,当我们使用jstack命令的时候其实是可以将死锁的信息给dump出来的,在dump结果的最后会有类似Found one Java-level deadlock:的关键字,接着会把发生死锁的线程的堆栈及对应的同步锁给打印出来,这次…