July 2013
Intermediate to advanced
370 pages
8h 27m
English
When we want to create a multiline string in Java, we have to use code like str += ...,
concatenated multiple lines using the + operator, or multiple calls to the
append
method of
StringBuilder or StringBuffer.
We’d have to use a lot of escape characters, and that usually is followed by a complaint that “there’s gotta be a better way to do that.”
In Groovy there is. We can define a multiline literal by enclosing the string within three single quotes
(”’…”’)—that’s Groovy’s support of here documents, or heredocs:
| WorkingWithStrings/MultilineStrings.groovy | |
| | memo = '''Several of you raised concerns about long meetings. |
| | To discuss this, we will be holding a 3 hour meeting starting |
| | at 9AM tomorrow. All ... |
Read now
Unlock full access