博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
java enummap_Java EnumMap size()方法与示例
阅读量:2531 次
发布时间:2019-05-11

本文共 1940 字,大约阅读时间需要 6 分钟。

java enummap

EnumMap类的size()方法 (EnumMap Class size() method)

  • size() method is available in java.util package.

    size()方法在java.util包中可用。

  • size() method is used to return the size of this enum map (i.e. it returns the number of key-value pairs exists in this enum map).

    size()方法用于返回此枚举映射的大小(即,它返回此枚举映射中存在的键值对的数量)。

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

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

  • size() method does not throw an exception at the time of returning the size of this map.

    返回此地图的大小时, size()方法不会引发异常。

Syntax:

句法:

public int size();

Parameter(s):

参数:

  • It does not accept any parameter.

    它不接受任何参数。

Return value:

返回值:

The return type of this method is int, it returns the number of key-value mappings exists in this enum map.

此方法的返回类型为int ,它返回此枚举映射中存在的键值映射数。

Example:

例:

// Java program to demonstrate the example // of int size() method of EnumMapimport java.util.*;public class SizeOfEnumMap {
public enum Colors {
RED, BLUE, PINK, YELLOW }; public static void main(String[] args) {
// We are creating EnumMap object EnumMap < Colors, String > em = new EnumMap < Colors, String > (Colors.class); // By using put() method is to // add the linked values in an // EnumMap (em) em.put(Colors.RED, "1"); em.put(Colors.BLUE, "2"); em.put(Colors.PINK, "3"); em.put(Colors.YELLOW, "4"); // Display EnumMap System.out.println("EnumMap (em) :" + em); // By using size() method isto // return the number of key-value // pairs exists in an EnumMap int size = em.size(); // Display Size Of An EnumMap System.out.println("em.size(): " + size); }}

Output

输出量

EnumMap (em) :{RED=1, BLUE=2, PINK=3, YELLOW=4}em.size(): 4

翻译自:

java enummap

转载地址:http://iqxzd.baihongyu.com/

你可能感兴趣的文章
AccountManager教程
查看>>
Android学习笔记(十一)——从意图返回结果
查看>>
算法导论笔记(四)算法分析常用符号
查看>>
HttpClient读取数据乱码的解决方案
查看>>
如何使用FireBug插件查询元素的xPath属性
查看>>
ultraedit激活
查看>>
总结(6)--- python基础知识点小结(细全)
查看>>
亿级曝光品牌视频的幕后设定
查看>>
ARPA
查看>>
JSP开发模式
查看>>
我的Android进阶之旅------&gt;Android嵌入图像InsetDrawable的使用方法
查看>>
Detours信息泄漏漏洞
查看>>
win32使用拖放文件
查看>>
Android 动态显示和隐藏软键盘
查看>>
raid5什么意思?怎样做raid5?raid5 几块硬盘?
查看>>
【转】how can i build fast
查看>>
接口测试-jmeter
查看>>
js便签笔记(5)——Dean Edwards大牛的跨浏览器AddEvent()设计(不知道是不是jQuery事件系统的原型)...
查看>>
重构wangEditor(web富文本编辑器),欢迎指正!
查看>>
null?对象?异常?到底应该如何返回错误信息
查看>>