Java multiline string

Posted by skiphoppy on Stack Overflow See other posts from Stack Overflow or by skiphoppy
Published on 2009-05-18T16:28:47Z Indexed on 2010/05/17 15:00 UTC
Read the original article Hit count: 286

Filed under:
|
|

Coming from Perl, I sure am missing the "here-document" means of creating a multi-line string in source code:

$string = <<"EOF"  # create a three line string
text
text
text
EOF

In Java I have to have cumbersome quotes and plus signs on every line as I concatenate my multiline string from scratch.

What are some better alternatives? Define my string in a properties file?

Edit: Two answers say StringBuilder.append() is preferable to the plus notation. Could anyone elaborate as to why they think so? It doesn't look more preferable to me at all. I'm looking for away around the fact that multiline strings are not a first-class language construct, which means I definitely don't want to replace a first-class language construct (string concatenation with plus) with method calls.

Edit: To clarify my question further, I'm not concerned about performance at all. I'm concerned about maintainability and design issues.

© Stack Overflow or respective owner

Related posts about java

Related posts about string