formatted() is an instance-method form of String.format on a text block.
String msg = "%s scored %d%%".formatted("Ava", 92);
System.out.println(msg);
Ava scored 92%
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