Text blocks are string literals that can comprise multiple lines of text and uses triple quotes (""") as its opening and closing delimiter.
Since Java 13, text blocks are available as a preview feature. Text blocks start with a “”” (three double-quote marks) followed by optional whitespace and a newline. The most simple example could look like:
String example = """
Example text""";
Note that the result type of a text block is still a String. Text blocks just provide us with another way to write String literals in our source code.
Inside the text blocks, we can freely use newlines and quotes without the need for escaping. It allows us to include literal fragments of HTML, JSON, SQL, or whatever we need, in a more elegant and readable way.
In the resulting String, the (base) indentation and the first newline are not included. We'll take a look at the handing of indentation in the next section.
Смотрите видео Java 15 new features | What are Text Blocks in Java 15 | Java Beam онлайн без регистрации, длительностью 06 минут 23 секунд в хорошем hd качестве. Это видео добавил пользователь Java Beam 20 Сентябрь 2020, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 1 тысяч раз и оно понравилось 12 людям.