Question

I've read that multiline string literals were proposed to be added in Java 7.

Although I can't find any documentation saying definitely that they have been. I'd like to know if they are, because this is something I'd consider switching versions for.

Was it helpful?

Solution

Multiline string literals are not going to be added to JDK 7. You can check Project Coin's homepage for a list of language changes.

However, you can use Scala, which does support multiline string literals using triple quotes:

var s = """Hello
      World"""

OTHER TIPS

Multiline strings were not added into Java (even as of Java 8, the newest current version), and probably will never be added to Java. However, you can add multiple strings together like so:

String greeting = "Hello " + 
    "world! " + 
    "This is a multiline string.";

Or, if you want the multiline line breaks to actually start a new line, insert "\n" to the end of each line.

Following Java's coding conventions Strings should be concatenated like:

String str = "Long text line " 
             + "more long text.";

Make sure the + operator always begins the next line for readability.
See: Code Conventions for the Java Programming Language: 4. Indentation

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top