Home » Java » Core Java » JEP 355 Text Blocks in JDK 13

About Mohamed Sanaulla

Mohamed Sanaulla

JEP 355 Text Blocks in JDK 13

JDK 13 went GA on September 17th, 2019 and the prominent new features are listed here. One of the new features is “text blocks”. This allows writing multiline strings easily without the need for concatenation while splitting into different lines.

Lets quickly look at the different ways of creating multiline strings:

String aBlock = """
SELECT id, first_name, last_name, dob
FROM person
WHERE id = ?

String aIndentedBlock = """
    SELECT id, first_name, last_name, dob
    FROM person
    WHERE id = ?

String anotherBlock = """
SELECT id, first_name, last_name, dob
FROM person
WHERE id = ?""";

System.out.println("This comes in the same line");

These are some of the invalid ways to write multiline string:

//        String thisIsInvalid = """This is invalid""";
//        String thisIsALsoInvalid = """THis is also invalid
//        """;

The text cannot start immediately after the opening quotes of the block i.e `”””` instead it has to start in the next line.

We can include “, ‘ in the multiline string:

        Block containing "" ' '

The end of block quotes can end in the same line as the text of in a new line:

String thisIsValid = """
This is valid""";

The complete code for this can be found here.

Published on Java Code Geeks with permission by Mohamed Sanaulla, partner at our JCG program. See the original article here: JEP 355 Text Blocks in JDK 13

Opinions expressed by Java Code Geeks contributors are their own.

(0 rating, 0 votes)
You need to be a registered member to rate this.
Start the discussion Views Tweet it!
Do you want to know how to develop your skillset to become a Java Rockstar?
Subscribe to our newsletter to start Rocking right now!
To get you started we give you our best selling eBooks for FREE!
1. JPA Mini Book
2. JVM Troubleshooting Guide
3. JUnit Tutorial for Unit Testing
4. Java Annotations Tutorial
5. Java Interview Questions
6. Spring Interview Questions
7. Android UI Design
and many more ....
I agree to the Terms and Privacy Policy
Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Inline Feedbacks
View all comments