A+ Computer Science
www.apluscompsci.com
A String is a group of characters. Strings are used to store words,
which can consist of letters, numbers, and symbols.
A+ Computer Science
www.apluscompsci.com
s is a String reference. s is storing the location / memory address of
the String Object "compsci";
champ is a String reference. champ is storing the location /
memory address of the String Object "uilstate";
A+ Computer Science
www.apluscompsci.com
s is a String reference. s is storing the location / memory address of
the String Object "compsci";
A+ Computer Science
www.apluscompsci.com
s is a String reference. s is storing the location / memory address of
the String Object "compsci";
A+ Computer Science
www.apluscompsci.com
A+ Computer Science
www.apluscompsci.com
A+ Computer Science
www.apluscompsci.com
String is an immutable Object. String cannot be changed. All of
the String methods are accessor method. All of the String methods
are return methods.
A+ Computer Science
www.apluscompsci.com
The String length() method returns the character count.
length() looks at the String Object and returns back the number
of characters contained.
compsci contains 7 characters so a call to length() would
return 7.
A+ Computer Science
www.apluscompsci.com
Return methods typically perform some action then send back
a value. Return methods are also used as get methods to
retrieve a value from an Object.
A+ Computer Science
www.apluscompsci.com
10
The String charAt() method returns the character at the specific
spot.
charAt(0) would return the character at spot 0.
charAt(2) would return the character at spot 2.
A+ Computer Science
www.apluscompsci.com
11
A+ Computer Science
www.apluscompsci.com
12
A+ Computer Science
www.apluscompsci.com
13
The String substring() method returns a String containing a
section from the original String.
A+ Computer Science
www.apluscompsci.com
14
The String substring() method returns a String containing a
section from the original String.
A+ Computer Science
www.apluscompsci.com
15
A+ Computer Science
www.apluscompsci.com
16
The String indexOf() method looks for a value and returns the
spot at which that value is stored. If the value provided is not
present in the String, -1 is returned. -1 would not be a valid spot in
the String which is why -1 was chosen as the return value when a
value is not found.
A+ Computer Science
www.apluscompsci.com
17
The String indexOf() method looks for a value and returns the
spot at which that value is stored. If the value provided is not
present in the String, -1 is returned. -1 would not be a valid spot in
the String which is why -1 was chosen as the return value when a
value is not found.
A+ Computer Science
www.apluscompsci.com
18
A+ Computer Science
www.apluscompsci.com
19
It is very common to add strings together make a new string.
Methods could be used as well as using the plus + operator.
A+ Computer Science
www.apluscompsci.com
20
A+ Computer Science
www.apluscompsci.com
21
A+ Computer Science
www.apluscompsci.com
22
A+ Computer Science
www.apluscompsci.com
23
Return methods typically perform some action then send back
a value. Return methods are also used as get methods to
retrieve a value from an Object.
A+ Computer Science
www.apluscompsci.com
24
Return methods typically perform some action then send back
a value. Return methods are also used as get methods to
retrieve a value from an Object.
A+ Computer Science
www.apluscompsci.com
25
Return methods typically perform some action then send back
a value. Return methods are also used as get methods to
retrieve a value from an Object.
A+ Computer Science
www.apluscompsci.com
26
Method twice is a return method. Method twice takes in
parameter x and then sends back x multiplied by 2.
A+ Computer Science
www.apluscompsci.com
27
Method twice is a return method. Method twice takes in
parameter x and then sends back x multiplied by 2.
A+ Computer Science
www.apluscompsci.com
28
A+ Computer Science
www.apluscompsci.com
29
A+ Computer Science
www.apluscompsci.com
30
toString() is used to display an Object. print() and
println() automatically call toString() when displaying an
Object reference. toString() typically sends back all
data/properties from an Object as one String.
A+ Computer Science
www.apluscompsci.com
31
A+ Computer Science
www.apluscompsci.com
32
A+ Computer Science
www.apluscompsci.com
33
A+ Computer Science
www.apluscompsci.com
34
A+ Computer Science
www.apluscompsci.com
35
A+ Computer Science
www.apluscompsci.com
36
A+ Computer Science
www.apluscompsci.com
37
A+ Computer Science
www.apluscompsci.com
38
A+ Computer Science
www.apluscompsci.com
39
A+ Computer Science
www.apluscompsci.com
40
A+ Computer Science
www.apluscompsci.com
41
A+ Computer Science
www.apluscompsci.com
42