ProLesson 3.5Beginner2 min readUpdated 30 October 2026
Text blocks and formatting
Write multi-line text cleanly with text blocks, and format numbers, money and tables with String.format and formatted().
Two modern tools make text much nicer to write: text blocks for multi-line text, and formatting for numbers, padding and tables.
01Text blocks (Java 15+)
Before text blocks, multi-line JSON or SQL inside Java meant lots of \n and +. A text block starts and ends with three double quotes:
TextBlock.java
public class TextBlock {
public static void main(String[] args) {
String json = """
{
"course": "Java",
"lessons": 95
}
""";
System.out.print(json);
String sql = """
SELECT name, email
FROM users
WHERE active = true
""";
System.out.print(sql);
}
}{
"course": "Java",
"lessons": 95
}
SELECT name, email
FROM users
WHERE active = true- The text starts on the line after the opening
""". - Java removes the common indentation, so you can indent the block with your code.
- Quotes inside don't need escaping.
- The closing
"""on its own line adds a final line break.
Loading the rest of the lesson…