Properties类propertyNames()方法
- propertyNames() 方法可在
java.util包。 - propertyNames() 方法用于返回此属性列表中存在的所有键的集合,它以枚举的形式包含默认属性列表中的唯一键。
 - propertyNames() 方法是一个非静态方法,它只能通过类对象访问,如果我们尝试使用类名访问方法,那么我们将得到一个错误。
 - propertyNames() 方法可能会在返回属性名称时抛出异常。
ClassCastException:当此属性列表中的任何现有键与字符串不兼容时,可能会抛出此异常 
用法:
public Enumeration propertyNames();
参数:
- 它不接受任何参数。
 
返回值:
该方法的返回类型是Enumeration,它返回此属性列表中存在的所有键的枚举以及默认属性列表中存在的唯一键。
例:
// Java program to demonstrate the example 
// of Enumeration propertyNames() method 
// of Properties
import java.io.*;
import java.util.*;
public class PropertyNamesOfProperties {
 public static void main(String arg[]) throws Exception {
  // Instantiate Properties object
  Properties prop = new Properties();
  prop.put("10", "C");
  prop.put("20", "C++");
  prop.put("30", "JAVA");
  prop.put("40", "PHP");
  prop.put("50", "SFDC");
  // By using propertyNames() method is to
  // returns the keys set in the form of an
  // Enumeration
  System.out.println("prop.propertyNames():");
  for (Enumeration en = prop.propertyNames(); en.hasMoreElements();)
   System.out.println(en.nextElement());
 }
}
输出
prop.propertyNames(): 40 50 10 20 30
相关用法
- Java Properties compute(Key, BiFunction)用法及代码示例
 - Java Properties containsKey(value)用法及代码示例
 - Java Properties computeIfAbsent(Key, Function)用法及代码示例
 - Java Properties entrySet()用法及代码示例
 - Java Properties loadFromXML()用法及代码示例
 - Java Properties getProperty(key)用法及代码示例
 - Java Properties getOrDefault(key, defaultValue)用法及代码示例
 - Java Properties stringPropertyNames()用法及代码示例
 - Java Properties hashCode()用法及代码示例
 - Java Properties isEmpty()用法及代码示例
 - Java Properties clone()用法及代码示例
 - Java Properties keySet()用法及代码示例
 - Java Properties forEach(BiConsumer)用法及代码示例
 - Java Properties containsValue(value)用法及代码示例
 - Java Properties elements()用法及代码示例
 - Java Properties setProperty()用法及代码示例
 - Java Properties computeIfPresent(Key, BiFunction)用法及代码示例
 - Java Properties keys()用法及代码示例
 - Java Properties equals(value)用法及代码示例
 - Java Properties get(key)用法及代码示例
 
注:本文由纯净天空筛选整理自Preeti Jain大神的英文原创作品 Java Properties propertyNames() Method with Example。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
