CHAPTER 5

image

String

The String class in Java is a data type that can hold string literals. String is a reference data type, as are all non-primitive data types. This means that the variable contains an address to an object in the memory, and not the object itself. A String object is created in the memory, and the address to the object is returned to the variable.

As seen below, string literals are delimited by double quotes. This is actually a shorthand notation for the regular reference type initialization (creation) syntax, which uses the new keyword.

String a = "Hello";String b = new String(" World");

Combining strings

The plus sign is used ...

Get Java Quick Syntax Reference 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.