DEV Community

msmittalas
msmittalas

Posted on

New way to Use Strings in Java 17

Before Java 15, Writing SQL, HTML, JSON or any Polyglot scripts in String were difficult. It was ugly and difficult to read.
For example :
Following HTML in Java :

Image description

OR

Following SQL in Java :

Image description

lot's of concatenation and escapes, It's difficult to read and write.

With "JEP 378: Text Blocks" introduced in Java 15 ( Java 17 LTS), We can use two dimensional block of text.

for example, above code can be rewritten in following way:

Following HTML in Java 17 :

Image description

Following SQL in Java 17 :

Image description

This way ,It's easy to read and write strings in Java.

More Details on :JEP-378

Happy Codding !!

Top comments (0)