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