String ring = "One ring to rule them all, " String find = "One ring to find them." ring = ring + find;
String objects don't change.
The reference variable
ring is changed in the
third statement to refer to a different
String becomes garbage, which
is collected by the garbage collector.)
The length of a string is the number of characters it contains, including space characters and punctuation. For example:
|" Look Out "||13|
An empty string has length zero.
length() method of a
String returns its length:
public int length();
The method takes no parameters, but the
() is needed
when it is used.
Inspect the following code:
String stringA = "Alphabet " ; String stringB = "Soup" ; String stringC = stringA + stringB; System.out.println( stringC.length() ) ;
What does the code print?