Using the String Class

In Java, you create strings by creating an instance of the String class. This String object can be created implicitly or explicitly depending on how the string is being used in the program. To create a string implicitly, you just place a string literal in your program, and Java automatically creates a String object for the string. This is because, even internally, Java uses String objects to represent string literals. Look at this line, for example:

String fullName = new String( "Mr. John Doe" );

Java implicitly creates a String object for the string literal "Mr. John Doe". Every time you refer to a string this way in a Java program, you're creating a String object.

The other way to create a String object is to explicitly ...

Get Special Edition Using Java 2 Standard Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.