What are Text Blocks (Java 13)

Text Blocks, introduced in Java 13 as a preview feature, provide a more readable and convenient way to represent multiline string literals in Java. They help reduce the need for escape sequences and make it easier to work with large chunks of text such as HTML, JSON, and SQL queries.

With Text Blocks, developers can encapsulate multiline strings using triple quotes ("""), thus improving code clarity and maintainability.

String textBlock = """ Once upon a time, in a land far, far away, there lived a brave knight. """;

Text Blocks Java 13 Multiline Strings Java Features Code Readability