package org.kodejava.util;
import java.util.Properties;
import java.util.Map;
import java.util.HashMap;
import java.util.Set;
public class PropertiesToMap {
public static void main(String[] args) {
// Create a new instance of Properties.
Properties properties = new Properties();
// Populate properties with a dummy application information
properties.setProperty("app.name", "HTML Designer");
properties.setProperty("app.version", "1.0");
properties.setProperty("app.vendor", "HTML Designer Inc");
// Create a new HashMap and pass an instance of Properties. Properties
// is an implementation of a Map which keys and values stored as in a
// String.
Map<Object, Object> map = new HashMap<>(properties);
// Get the entry set of the Map and print it out.
Set<Map.Entry<Object, Object>> propertySet = map.entrySet();
for (Map.Entry<Object, Object> entry : propertySet) {
System.out.printf("%s = %s%n", entry.getKey(), entry.getValue());
}
}
}
The output of the code snippet above:
app.vendor = HTML Designer Inc
app.name = HTML Designer
app.version = 1.0
Latest posts by Wayan (see all)
- How do I get number of each day for a certain month in Java? - September 8, 2024
- How do I get operating system process information using ProcessHandle? - July 22, 2024
- How do I sum a BigDecimal property of a list of objects using Java Stream API? - July 22, 2024