Skip to content

io microsphere collection PropertiesUtils

github-actions[bot] edited this page May 30, 2026 · 12 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.6-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

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.

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
`

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