Java SE API
Formatter.format()
Write formatted output to this formatter. Java SE API; example uses Java 21-compatible syntax.
Formal Syntax & Structure
java syntaxjava
Formatter format(String format, Object... args)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| format | String | Format string |
| args | Object... | Format arguments |
Return Value
Formatter
Write formatted output to this formatter.
Working Example
Example Snippetjava
import java.util.*;import java.util.regex.*;import java.nio.*;import java.nio.charset.*;import java.io.*;import javax.xml.XMLConstants;import javax.xml.parsers.*;import org.xml.sax.*;import org.xml.sax.helpers.DefaultHandler;import org.w3c.dom.*;public class Main { public static void main(String[] args) throws Exception { var joiner = new StringJoiner(" | ", "[", "]"); try (var scanner = new Scanner("12 7 stop").useLocale(Locale.ROOT); var formatter = new Formatter(Locale.ROOT)) { while (scanner.hasNextInt()) joiner.add(Integer.toString(scanner.nextInt())); formatter.format("%s: %04d", scanner.next(), 19); System.out.println(joiner); System.out.println(formatter); } }}