Core Java: Text blocks strip incidental indentation based on the closing delimiter

A text block's common leading whitespace is stripped using the least-indented line, including the closing triple-quote, so moving the closing delimiter changes how much indentation survives.

Code
String block = """
        Hello
          World
        """;
System.out.println("[" + block + "]");
System.out.println("Length: " + block.length());
Output
[Hello
  World
]
Length: 14
Advertisement
More in JAVA

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-09-27

© Java Coding Hub · About · Contact · Privacy · Terms