4.2. Strings

A string is a discrete series of adjacent characters. A string is distinct from the primitive types in that it is a standard class. A string literal is a set of zero or more characters surrounded by double quotes:

String name = new String("JJ"); 

Strings are used very frequently, so Java makes available a shortcut for string creation and initialization, like this:

String name = "JJ"; 

This longer version, called a constructor, represents the way in which objects are created. The shorter version is called a string literal. String literals are implicitly created as instances of the java.lang.String class, and as such, a variable defined as a string holds a reference to a String object. Because string literals act as if they were ...

Get Java™ for ColdFusion® Developers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.