Text blocks keep multi-line strings readable

A text block strips the common indentation, so embedded JSON or SQL stays aligned with the code without escape characters.

Code
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());
Output
{
  "tool": "JSON Formatter",
  "free": true
}
---
SELECT id, email
FROM users
WHERE enabled = 1
--- lines: 3
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-30