Java.util.Properties.propertyNames() Method



Description

The java.util.Properties.propertyNames() method Returns an enumeration of all the keys in this property list, including distinct keys in the default property list if a key of the same name has not already been found from the main properties list.

Declaration

Following is the declaration for java.util.Properties.propertyNames() method

public Enumeration<?> propertyNames()

Parameters

NA

Return Value

This method returns an enumeration of all the keys in this property list, including the keys in the default property list.

Exception

ClassCastException − if any key in this property list is not a string.

Example

The following example shows the usage of java.util.Properties.propertyNames() method.

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());
   }
}

Let us compile and run the above program, this will produce the following result −

Width
Height
java_util_properties.htm
Advertisements