Skip to content

io microsphere collection PropertiesUtils

github-actions[bot] edited this page Jun 9, 2026 · 14 revisions

PropertiesUtils

Type: Class | Module: microsphere-java-core | Package: io.microsphere.collection | Since: 1.0.0

Source: microsphere-java-core/src/main/java/io/microsphere/collection/PropertiesUtils.java

Overview

The utilities class for Properties

Declaration

public abstract class PropertiesUtils implements Utils

Author: Mercy

Version Information

  • Introduced in: 1.0.0
  • Current Project Version: 0.3.8-SNAPSHOT

Version Compatibility

This component is tested and compatible with the following Java versions:

Java Version Status
Java 8 ✅ Compatible
Java 11 ✅ Compatible
Java 17 ✅ Compatible
Java 21 ✅ Compatible
Java 25 ✅ Compatible

Examples

Method Examples

newProperties

{
  "a": "1",
  "b": {
    "c": "2",
    "d": {
      "e": "3"
    }
  }
}
{
  "a": "1",
  "b.c": "2",
  "b.d.e": "3"
}
Properties props = PropertiesUtils.newProperties();
    System.out.println(props.isEmpty()); // Output: true

    props.setProperty("key", "value");
    System.out.println(props); // Output: {key=value}

newProperties

Properties defaults = new Properties();
    defaults.setProperty("default.key", "default.value");
    Properties props = PropertiesUtils.newProperties(defaults);
    System.out.println(props.getProperty("default.key")); // Output: default.value

loadProperties

// Load properties from multiple lines
    Properties props = PropertiesUtils.loadProperties(
        "key1=value1",
        "key2=value2"
    );
    System.out.println(props.getProperty("key1")); // Output: value1
    System.out.println(props.getProperty("key2")); // Output: value2

    // Load empty properties if no arguments are provided
    Properties emptyProps = PropertiesUtils.loadProperties();
    System.out.println(emptyProps.isEmpty()); // Output: true

Usage

Maven Dependency

Add the following dependency to your pom.xml:

<dependency>
    <groupId>io.github.microsphere-projects</groupId>
    <artifactId>microsphere-java-core</artifactId>
    <version>${microsphere-java.version}</version>
</dependency>

Tip: Use the BOM (microsphere-java-dependencies) for consistent version management. See the Getting Started guide.

Import

import io.microsphere.collection.PropertiesUtils;

API Reference

Public Methods

Method Description
newProperties Flattens a nested map of properties into a single-level map.
newProperties Creates a new Properties instance with the specified defaults.
loadProperties Loads properties from the given string values.

Method Details

newProperties

public static Properties newProperties()

Flattens a nested map of properties into a single-level map.

If the input map is empty or null, the same map instance is returned.

For example, given the following input:

`{
  "a": "1",
  "b": {
    "c": "2",
    "d": {
      "e": "3"
    `
  }
}
}

The resulting flattened map would be:

`{
  "a": "1",
  "b.c": "2",
  "b.d.e": "3"
`
}

newProperties

public static Properties newProperties(Properties defaults)

Creates a new Properties instance with the specified defaults.

This method provides a convenient way to create a properties object with default properties.

Example Usage

`Properties defaults = new Properties();
    defaults.setProperty("default.key", "default.value");
    Properties props = PropertiesUtils.newProperties(defaults);
    System.out.println(props.getProperty("default.key")); // Output: default.value
`

loadProperties

public static Properties loadProperties(String... propertiesValue)

Loads properties from the given string values.

The provided string values are joined using the system file separator to form a single content string, which is then parsed as a standard Java properties format.

Example Usage

`// Load properties from multiple lines
    Properties props = PropertiesUtils.loadProperties(
        "key1=value1",
        "key2=value2"
    );
    System.out.println(props.getProperty("key1")); // Output: value1
    System.out.println(props.getProperty("key2")); // Output: value2

    // Load empty properties if no arguments are provided
    Properties emptyProps = PropertiesUtils.loadProperties();
    System.out.println(emptyProps.isEmpty()); // Output: true
`

This documentation was auto-generated from the source code of microsphere-java.

Home

annotation-processor

java-annotations

java-core

java-test

jdk-tools

lang-model

Clone this wiki locally