sebastiandaschner blog


What You Need to Know About Java Text Blocks

#java thursday, november 10, 2022

In this video I’ll explain what you need to know about Java Text Blocks (JEP 378), how to use them, and why you should care:

 

 

Takeaways

  • Text blocks were fully released in JDK 15

  • Text blocks are placed in between two """, with a line break after the first one

  • Incidental white space will be removed; the line with least amount counts

  • For intended left-trailing white space, use indentation of closing """

  • For intended right-trailing white space, use escape \s

  • For escaping incidental line breaks, use escape \

  • For escaping """, use \"""

  • For replacing variables, use String's format(), replace(), or formatted() methods

  • Check out JEP 378: Text Blocks

 

Found the post useful? Subscribe to my newsletter for more free content, tips and tricks on IT & Java: