The Java Properties class is a class which represents a persistent set of properties. The Properties can be saved to a stream or loaded from a stream. Following are the important points about Properties −
Each key and its corresponding value in the property list is a string.
A property list can contain another property list as its 'defaults', this second property list is searched if the property key is not found in the original property list.
This class is thread-safe; multiple threads can share a single Properties object without the need for external synchronization.
Following is the declaration for java.util.Properties class −
public class Properties extends Hashtable<Object,Object>Field
Following are the fields for java.util.Properties class −
protected Properties defaults − This is the property list that contains default values for any keys not found in this property list.
Class constructors Sr.No. Constructor & Description 1Properties()
This constructs creates an empty property list with no default values.
2Properties(int initialCapacity)
This constructs creates an empty property list with no default values, and with an initial size accommodating the specified number of elements without the need to dynamically resize.
3Properties(Properties defaults)
This constructs creates an empty property list with the specified defaults.
Class methods Methods inheritedThis class inherits methods from the following classes −
The following example shows the usage of java.util.Properties.propertyNames() method.
package com.tutorialspoint; import java.util.Enumeration; import java.util.Properties; 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 while(enumeration.hasMoreElements()) { System.out.println("" + enumeration.nextElement()); } } }Output
Let us compile and run the above program, this will produce the following result −
Width Height
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4