Java Reference
In-Depth Information
11 System.out.println(sound + ",");
12 System.out.println(sound + ".");
13 System.out.println("The " + item + " on the bus " +
14 verb + " " + sound + ",");
15 System.out.println("All through the town.");
16 System.out.println();
17 }
18 }
It produces the following output:
The wheels on the bus go round and round,
round and round,
round and round.
The wheels on the bus go round and round,
All through the town.
The wipers on the bus go swish, swish, swish,
swish, swish, swish,
swish, swish, swish.
The wipers on the bus go swish, swish, swish,
All through the town.
The horn on the bus goes beep, beep, beep,
beep, beep, beep,
beep, beep, beep.
The horn on the bus goes beep, beep, beep,
All through the town.
Table 3.3 lists some of the most useful methods that you can call on String objects.
Strings in Java are immutable, which means that once they are constructed, their
values can never be changed.
Immutable Object
An object whose value cannot be changed.
It may seem odd that strings are immutable and yet have methods like
toUpperCase and toLowerCase . But if you read the descriptions in the table
carefully, you'll see that these methods don't actually change a given String object;
instead they return a new string. Consider the following code:
String s = "Hello Maria";
s.toUpperCase();
System.out.println(s);
 
Search WWH ::




Custom Search