热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Java中的属性元素()方法,示例

Java 中的属性元素()方法,示例原文:https://www . geesforgeks . org/properties-

Java 中的属性元素()方法,示例

原文:https://www . geesforgeks . org/properties-elements-method-in-Java-with-examples/

属性类元素()方法用于获取该属性对象的枚举。它还可以用于使用接收到的枚举按顺序检索元素。

语法:

public Enumeration elements()

参数:该方法不接受任何参数。
返回:该方法返回该属性对象中值的枚举
以下程序说明了元素()方法:
程序 1:

Java 语言(一种计算机语言,尤用于创建网站)


// Java program to demonstrate
// elements() method.
import java.util.*;
public class GFG {
    // Main method
    public static void main(String[] args)
    {
        // Create a properties and add some values
        Properties properties = new Properties();
        properties.put("Pen", 10);
        properties.put("Book", 500);
        properties.put("Clothes", 400);
        properties.put("Mobile", 5000);
        // Print Properties details
        System.out.println("Current Properties: "
                           + properties.toString());
        // Creating an empty enumeration to store
        Enumeration enu = properties.elements();
        System.out.println("The enumeration of values are:");
        // Displaying the Enumeration
        while (enu.hasMoreElements()) {
            System.out.println(enu.nextElement());
        }
    }
}

Output: 

Current Properties: {Book=500, Mobile=5000, Pen=10, Clothes=400}
The enumeration of values are:
500
5000
10
400


推荐阅读
author-avatar
ghsk
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有