Language beginner

Text blocks for multiline strings

Write multiline strings naturally with triple-quote text blocks.

✕ Java 8
String json = "{\n" +
    "  \"name\": \"Duke\",\n" +
    "  \"age\": 30\n" +
    "}";
✓ Java 15+
String json = """
    {
      "name": "Duke",
      "age": 30
    }
    """;
📖

Readable as-is

JSON, SQL, and HTML look like real JSON, SQL, and HTML in your source.

🚫

No escape hell

Embedded quotes don't need backslash escaping.

📐

Smart indentation

Leading whitespace is trimmed automatically based on the closing delimiter position.

Old Approach
String Concatenation
Modern Approach
Text Blocks
Since JDK
15
Difficulty
beginner
Text blocks for multiline strings
Available

Widely available since JDK 15 (Sept 2020)

How it works

Text blocks let you write multiline strings exactly as they appear. No more escaping quotes or adding \n. The compiler strips incidental indentation automatically.

Share 𝕏 🦋 in