Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

14
  • 274
    Furthermore, the first version will be automatically concatenated by the compiler, since all the strings are known at compile time. Even if the strings are not known at compile time, it's no slower than StringBuilder or String.format(). The only reason to avoid concatenation with +'s is if you're doing it in a loop. Commented May 18, 2009 at 17:06
  • 30
    The problem with the String.format version is that you have to keep the format in sync with the number of lines. Commented Dec 14, 2010 at 12:05
  • 6
    String.format is not efficient compared to other two examples Commented Dec 30, 2010 at 0:50
  • 12
    This answer is a very inappropriate solution to the question at hand. We have 2000 line SAS macros or bunches of 200 line SQL queries which we wish to copy and paste. To suggest that we use +"" concat to transform those multiline text into StringBuffer appends is ridiculous. Commented Sep 24, 2012 at 19:44
  • 26
    @BlessedGeek: the question at hand was about what options were available in the Java language. It didn't mention anything about the type of data going into the string. If there is a better solution then you can post it as an answer. It sounds like Josh Curren's solution would be better for your situation. If you are just upset that the language doesn't support multiline literals then this is the wrong place to complain about it. Commented Sep 24, 2012 at 20:08