Multi-line strings in Java are finally here in the form of Text blocks. It’s available as a preview feature. So you need to use the switches ––enable-preview and ––release 13 or –release 14 while compiling and executing this code.
public class TextBlocks {
public static void main(String[] args) {
String message = """
Corona Alert!!!
Lockdown for 21 days!
Stay calm!
""";
System.out.println(message);
}
}
Compile it using
javac ––enable-preview ––release 13 TextBlocks.java
And when you run it java –enable-preview TextBlocks, you get the following output with the formatting preserved. The compiler also works towards removing trailing whitespaces and meaningless indentations.
