In the spirit of this question: https://stackoverflow.com/questions/1886966/java-string-declaration-occupying-multiple-lines
will there be any plans in any future version of Java to allow string continuation in the java scource?
String haveUeverSeenLorem =
"Lorem ipsum dolor sit amet, \
consectetur adipisicing elit, \
sed do eiusmod tempor incididunt \
ut labore et dolore magna aliqua.";
Either one way or another, e.g. like the above example.
The good news is that Java 15 has native support for multiline strings via Text Blocks. All the other methods reviewed can be used in Java 15 or any previous version. The code for all the methods in this article is available over on GitHub.
There are three ways to create strings that span multiple lines: By using template literals. By using the + operator – the JavaScript concatenation operator. By using the \ operator – the JavaScript backslash operator and escape character.
It was proposed for inclusion in Java 7 but was rejected.
It was proposed again for Java 8 but did not make it to the final version.
Java 9's JEP 213: Milling Project Coin does not include anything regarding multine strings either.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With