A text block strips the common indentation, so embedded JSON or SQL stays aligned with the code without escape characters.
String json = """
{
"tool": "JSON Formatter",
"free": true
}""";
System.out.println(json);
String sql = """
SELECT id, email
FROM users
WHERE enabled = 1""";
System.out.println("---");
System.out.println(sql);
System.out.println("--- lines: " + sql.lines().count());
{
"tool": "JSON Formatter",
"free": true
}
---
SELECT id, email
FROM users
WHERE enabled = 1
--- lines: 3
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-30