目录

Enumeration<?> propertyNames()

描述 (Description)

java.util.Properties.propertyNames()方法返回此属性列表中所有键的枚举,如果尚未从主属性列表中找到相同名称的键,则包括默认属性列表中的不同键。

声明 (Declaration)

以下是java.util.Properties.propertyNames()方法的声明

public Enumeration<?> propertyNames()

参数 (Parameters)

NA

返回值 (Return Value)

此方法返回此属性列表中所有键的枚举,包括默认属性列表中的键。

异常 (Exception)

ClassCastException - 如果此属性列表中的任何键不是字符串。

例子 (Example)

以下示例显示了java.util.Properties.propertyNames()方法的用法。

package com.iowiki;
import java.util.*;
public class PropertiesDemo {
   public static void main(String[] args) {
      Properties prop = new Properties();
      // add some properties
      prop.put("Height", "200");
      prop.put("Width", "15");
      // assign the property names in a enumaration
      Enumeration<?> enumeration = prop.propertyNames();
      // print the enumaration elements
      System.out.println("" + enumeration.nextElement());
      System.out.println("" + enumeration.nextElement());
   }
}

让我们编译并运行上面的程序,这将产生以下结果 -

Width
Height
↑回到顶部↑
WIKI教程 @2018