Java SE API
String.format(Locale, String, Object...)
Format with specified locale (null means no localization); invalid format or incompatible arguments may throw IllegalFormatException.
Formal Syntax & Structure
java syntaxjava
public static String format(Locale l, String format, Object... args)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| l | Locale | Formatting locale. |
| format | String | Format string. |
| args | Object... | Placeholder arguments. |
Return Value
String
Formatted text.
Working Example
Example Snippetjava
import java.util.Locale;public class Main { public static void main(String[] args) { String line = String.format(Locale.ROOT, "Weight: %.2f kg", 2.5); String header = """ Dispatch Ready """; System.out.print(header); System.out.println(line); }}