Strings beginner

Multiline JSON/SQL/HTML

Write SQL, JSON, and HTML as they actually look.

✕ Java 8
String sql =
    "SELECT u.name, u.email\n" +
    "FROM users u\n" +
    "WHERE u.active = true\n" +
    "ORDER BY u.name";
✓ Java 15+
String sql = """
    SELECT u.name, u.email
    FROM users u
    WHERE u.active = true
    ORDER BY u.name""";
📋

Copy-paste

Paste SQL/JSON directly from other tools.

📖

Readable

The string looks like the actual SQL/JSON output.

🔧

Maintainable

Easy to edit — no hunting for \n and + operators.

Old Approach
Escaped Strings
Modern Approach
Text Blocks
Since JDK
15
Difficulty
beginner
Multiline JSON/SQL/HTML
Available

Widely available since JDK 15 (Sept 2020)

Text blocks make embedded languages readable. Copy SQL from your database tool and paste it directly. The closing delimiter position controls indentation stripping.

Share 𝕏 🦋 in