The String and StringBuffer Classes

The String and StringBuffer classes are used to support operations on strings of characters. The String class supports constant (unchanging or immutable) strings, whereas the StringBuffer class supports expandable, modifiable strings. String objects are more compact than StringBuffer objects, but StringBuffer objects are more flexible.

String Literals

String literals are strings that are specified using double quotes. "This is a string" and "xyz" are examples of string literals. String literals are different from the literal values used with primitive types.

When the javac compiler encounters a String literal, it converts it to a String constructor. For example, the following:

String str = "text";

is equivalent ...

Get Sun Certification Training Guide (310-025, 310-027): Java™ 2 Programmer and Developer Exams 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.