String.format builds strings using printf-style conversion specifiers.
String s = String.format("%-6s|%5.2f|%,d", "Ava", 3.14159, 1000000);
System.out.println(s);
Ava | 3.14|1,000,000
Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.
Published 2026-07-26