text block
A multi-line string literal opened and closed by three double quotes, whose common indentation is removed automatically.
In more detail
Text blocks keep JSON fixtures, SQL and example requests readable in code. They are still plain strings: they do not parse or validate JSON. Combine one with the formatted method to fill in values, but use a real serializer such as Jackson for production output.
Example
return """
{"status": "ready"}
""";Related terms
- string — A sequence of characters, that is, a piece of text.
- literal — A value written directly in source code, such as 42, 3.5, "hi" or true.
- JSON — A simple text format for structured data made of keys, values, lists and nested objects.
- serialization — Turning an in-memory object into bytes, such as JSON text, that can be sent or stored, and parsing it back again.
Taught in
- Pattern Matching And Text Blocks — Modern Java: Virtual Threads & High-Throughput Services
- Promotion, Wrappers And The Math API — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Strings, StringBuilder And Text Blocks — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Sprint: Values And Flow — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Mock Exam: Sit It, Score It — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep