The Java Version Almanac
javaalmanac.io
Feedback on this page?

Text Blocks

Text blocks allow multiline strings literals.

Since Java 15

public class TextBlocks { static final String LINK_TEMPLATE = """ <a href="%s">Click here!</a>"""; public static void main(String... args) { // Text blocks always start with three double quotes and a new line: String greeting = """ Hello "World"! """; System.out.println(greeting); System.out.println(LINK_TEMPLATE.formatted("https://javaalmanac.io/")); } }

This snippet at GitHub