10 String and String Buffer

10.1 THE STRING CLASS

The String class represents character strings. All string literals in Java programs, such as hello,1234 and xyz123 are implemented as instances of this class. Strings are constants and their values cannot be changed after they are created. String buffers support mutable strings, i.e., which can be modified. They will be discussed in the next section. Since String objects are immutable, they can be shared.

The declaration of String class from the Java documentation is given below.

public final class String extends Object implements Serializable,
Comparable<String>, CharSequence

This states that String is a final class and object is its super class. The class implements three interfaces.

As an ...

Get Java Programming now with O’Reilly online learning.

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