Java.util.Properties.propertyNames() 方法
描述
java.util.Properties.propertyNames() 方法返回此属性列表中所有键的枚举,如果尚未找到同名键,则包括默认属性列表中的不同键 从主要属性列表中。
声明
以下是 java.util.Properties.propertyNames() 方法的声明
public Enumeration<?> propertyNames()
参数
NA
返回值
此方法返回此属性列表中所有键的枚举,包括默认属性列表中的键。
异常
ClassCastException − 如果此属性列表中的任何键不是字符串。
示例
下面的例子展示了 java.util.Properties.propertyNames() 方法的使用。
package com.tutorialspoint;
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

