Skip to content

io microsphere text FormatUtils

github-actions[bot] edited this page Mar 21, 2026 · 1 revision

FormatUtils

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

Source: microsphere-java-core/src/main/java/io/microsphere/text/FormatUtils.java

Overview

The utility class of text format

Declaration

public abstract class FormatUtils implements Utils

Author: Mercy

Version Information

  • Introduced in: 1.0.0
  • Current Project Version: 0.1.10-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

format

format("Hello, {}", "World") => "Hello, World"
format("{} + {} = 4", 2, 2) => "2 + 2 = 4"
format("No replacement here", "extra") => "No replacement here"

formatWithPlaceholder

formatWithPlaceholder("Hello, [placeholder]", "[placeholder]", "World") => "Hello, World"
formatWithPlaceholder("[placeholder] + [placeholder] = 4", "[placeholder]", 2, 2) => "2 + 2 = 4"
formatWithPlaceholder("No replacement here", "[placeholder]", "extra") => "No replacement here"

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.text.FormatUtils;

API Reference

Public Methods

Method Description
format Formats the given pattern by replacing all occurrences of the default placeholder
formatWithPlaceholder Formats the given pattern by replacing all occurrences of the specified placeholder

Method Details

format

public static String format(String pattern, Object... args)

Formats the given pattern by replacing all occurrences of the default placeholder (#DEFAULT_PLACEHOLDER) with corresponding values from the provided arguments.

If there are more placeholders in the pattern than arguments provided, extra placeholders will remain unchanged.

Example Usage

`format("Hello, {`", "World") => "Hello, World"
format("{} + {} = 4", 2, 2) => "2 + 2 = 4"
format("No replacement here", "extra") => "No replacement here"
}

formatWithPlaceholder

public static String formatWithPlaceholder(String pattern, String placeholder, Object... args)

Formats the given pattern by replacing all occurrences of the specified placeholder with corresponding values from the provided arguments.

If there are more placeholders in the pattern than arguments provided, extra placeholders will remain unchanged.

Example Usage

`formatWithPlaceholder("Hello, [placeholder]", "[placeholder]", "World") => "Hello, World"
formatWithPlaceholder("[placeholder] + [placeholder] = 4", "[placeholder]", 2, 2) => "2 + 2 = 4"
formatWithPlaceholder("No replacement here", "[placeholder]", "extra") => "No replacement here"
`

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

Home

java-annotations

java-core

jdk-tools

lang-model

annotation-processor

java-test

Clone this wiki locally