concept string literal in category groovy

appears as: string literals, string literal
Groovy in Action, Second Edition

This is an excerpt from Manning's book Groovy in Action, Second Edition.

Just as in Java, character data is mostly handled using the java.lang.String class. But Groovy provides some tweaks to make that easier, with more options for string literals and some helpful operators.

3.4.1. Varieties of string literals

Java allows only one way of specifying string literals: placing text in quotes “like this.” If you want to embed dynamic values within the string, you have to either call a formatting method (made easier, but still far from simple, in Java 1.5) or concatenate each constituent part. If you specify a string with a lot of backslashes in it (such as a Windows filename or a regular expression), your code becomes hard to read, because you have to double the backslashes. If you want a lot of text spanning several lines in the source code, you have to make each line contain a complete string (or several complete strings).

Groovy recognizes that not every use of string literals is the same, so it offers a variety of options. These are summarized in table 3.5.

sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest