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 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.