Java 15: String.formatted for inline formatting

formatted() is an instance-method form of String.format on a text block.

Code
String msg = "%s scored %d%%".formatted("Ava", 92);
System.out.println(msg);
Output
Ava scored 92%
Advertisement

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