THE Java™ Programming Language, Fourth Edition

(Jeff_L) #1
Returns the char in this sequence at the given index. Sequences are
indexed from zero to length()-1 (just as arrays are indexed). As this is a
UTF-16 sequence of characters, the returned value may be an actual character
or a value that is part of a surrogate pair. If the index is negative or not less
than the length of the sequence, then an IndexOutOfBoundsException
is thrown.

public intlength()

Returns the length of this character sequence.

public CharSequencesubSequence(int start, int end)

Returns a new CharSequence that contains the char values in this
sequence consisting of charAt(start) through to charAt(end-1). If
start is less than end or if use of either value would try to index outside
this sequence, then an IndexOutOfBoundsException is thrown. Be
careful to ensure that the specified range doesn't split any surrogate pairs.

public StringtoString()

Overrides the contract of Object.toString to specify that it returns the
character sequence represented by this CharSequence.

13.2. The String Class


Strings are immutable (read-only) character sequences: Their contents can never be changed after the string is
constructed. The String class provides numerous methods for working with stringssearching, comparing,
interacting with other character sequencesan overview of which is given in the following sections.


13.2.1. Basic String Operations


You can create strings implicitly either by using a string literal (such as "Gröçe") or by using + or += on
two String objects to create a new one.


You can also construct String objects explicitly using new. The String class supports the following
simple constructors (other constructors are shown in later sections):


publicString()

Constructs a new String with the value ""an empty string.

publicString(String value)

Constructs a new String that is a copy of the specified String object
valuethis is a copy constructor. Because String objects are immutable,
this is rarely used.

publicString(StringBuilder value)
Free download pdf