
🎓 Java Text Blocks Syntax
With a Touch of French Literature
Java introduced text blocks to make it easier to write multi-line strings without having to concatenate lines or escape special characters like quotes and newlines.
🧱 Syntax of a Text Block
A text block starts with three double-quote characters (""") followed by a line terminator. That means you cannot begin writing content on the same line as the opening triple quotes.
✅ But this is perfectly valid:
This is equivalent to:
📚 Quoting French Authors with Text Blocks
Let's now look at some classic French quotes using text blocks.
Compared to the traditional way:
Notice how cleaner and more readable the text block version is—no need to escape quotes or manually add newline characters.
💡 Code Example Inside a Text Block
Text blocks are also great for embedding code:
Which would traditionally be written as:
✨ Summary
Text blocks simplify writing multi-line strings, whether you're listing values or quoting literary giants. Just remember:
🟣 Start with """ followed by a newline.
🟣 Indentation is preserved but can be trimmed automatically.
🟣 Quotes inside don’t need to be escaped.