Properties Enumeration propertyNames() method Example Program


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.

Program

package com.candidjava;
import java.util.Enumeration;
import java.util.Properties;
/* 
 * @author : Mohan 
 * @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. 
 */
public class PropertiesNames {
	public static void main(String[] args) {
		Properties prop = new Properties();

		// add some properties
		prop.put("1", "karthi");
		prop.put("2", "kamal");
		prop.put("3", "hari");

		// 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());
		System.out.println("" + enumeration.nextElement());

	}
}

Output

3
2
1

Explanation

public Enumeration<?> propertyNames()
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.
Returns:
an enumeration of all the keys in this property list, including the keys in the default property list.
Throws:
ClassCastException - if any key in this property list is not a string.
See Also:
Enumeration, defaults, stringPropertyNames()


Related Post

Comments


©candidjava.com