strings methods slides java aplus

42
©A+ Computer Science www.apluscompsci.com 1

Upload: gabby-sanchez

Post on 05-Jan-2016

44 views

Category:

Documents


6 download

DESCRIPTION

APLUS Comp Sci Presentation

TRANSCRIPT

Page 1: Strings Methods Slides Java Aplus

©A+ Computer Science www.apluscompsci.com 1

Page 2: Strings Methods Slides Java Aplus

©A+ Computer Science www.apluscompsci.com 2

A String is a group of characters. Strings are used to store words,

which can consist of letters, numbers, and symbols.

Page 3: Strings Methods Slides Java Aplus

©A+ Computer Science www.apluscompsci.com 3

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";

Page 4: Strings Methods Slides Java Aplus

©A+ Computer Science www.apluscompsci.com 4

s is a String reference. s is storing the location / memory address of

the String Object "compsci";

Page 5: Strings Methods Slides Java Aplus

©A+ Computer Science www.apluscompsci.com 5

s is a String reference. s is storing the location / memory address of

the String Object "compsci";

Page 6: Strings Methods Slides Java Aplus

©A+ Computer Science www.apluscompsci.com 6

Page 7: Strings Methods Slides Java Aplus

©A+ Computer Science www.apluscompsci.com 7

Page 8: Strings Methods Slides Java Aplus

©A+ Computer Science www.apluscompsci.com 8

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.

Page 9: Strings Methods Slides Java Aplus

©A+ Computer Science www.apluscompsci.com 9

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.

Page 10: Strings Methods Slides Java Aplus

©A+ Computer Science www.apluscompsci.com 10

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.

Page 11: Strings Methods Slides Java Aplus

©A+ Computer Science www.apluscompsci.com 11

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.

Page 12: Strings Methods Slides Java Aplus

©A+ Computer Science www.apluscompsci.com 12

Page 13: Strings Methods Slides Java Aplus

©A+ Computer Science www.apluscompsci.com 13

Page 14: Strings Methods Slides Java Aplus

©A+ Computer Science www.apluscompsci.com 14

The String substring() method returns a String containing a

section from the original String.

Page 15: Strings Methods Slides Java Aplus

©A+ Computer Science www.apluscompsci.com 15

The String substring() method returns a String containing a

section from the original String.

Page 16: Strings Methods Slides Java Aplus

©A+ Computer Science www.apluscompsci.com 16

Page 17: Strings Methods Slides Java Aplus

©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.

Page 18: Strings Methods Slides Java Aplus

©A+ Computer Science www.apluscompsci.com 18

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.

Page 19: Strings Methods Slides Java Aplus

©A+ Computer Science www.apluscompsci.com 19

Page 20: Strings Methods Slides Java Aplus

©A+ Computer Science www.apluscompsci.com 20

It is very common to add strings together make a new string.

Methods could be used as well as using the plus + operator.

Page 21: Strings Methods Slides Java Aplus

©A+ Computer Science www.apluscompsci.com 21

Page 22: Strings Methods Slides Java Aplus

©A+ Computer Science www.apluscompsci.com 22

Page 23: Strings Methods Slides Java Aplus

©A+ Computer Science www.apluscompsci.com 23

Page 24: Strings Methods Slides Java Aplus

©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.

Page 25: Strings Methods Slides Java Aplus

©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.

Page 26: Strings Methods Slides Java Aplus

©A+ Computer Science www.apluscompsci.com 26

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.

Page 27: Strings Methods Slides Java Aplus

©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.

Page 28: Strings Methods Slides Java Aplus

©A+ Computer Science www.apluscompsci.com 28

Method twice is a return method. Method twice takes in

parameter x and then sends back x multiplied by 2.

Page 29: Strings Methods Slides Java Aplus

©A+ Computer Science www.apluscompsci.com 29

Page 30: Strings Methods Slides Java Aplus

©A+ Computer Science www.apluscompsci.com 30

Page 31: Strings Methods Slides Java Aplus

©A+ Computer Science www.apluscompsci.com 31

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.

Page 32: Strings Methods Slides Java Aplus

©A+ Computer Science www.apluscompsci.com 32

Page 33: Strings Methods Slides Java Aplus

©A+ Computer Science www.apluscompsci.com 33

Page 34: Strings Methods Slides Java Aplus

©A+ Computer Science www.apluscompsci.com 34

Page 35: Strings Methods Slides Java Aplus

©A+ Computer Science www.apluscompsci.com 35

Page 36: Strings Methods Slides Java Aplus

©A+ Computer Science www.apluscompsci.com 36

Page 37: Strings Methods Slides Java Aplus

©A+ Computer Science www.apluscompsci.com 37

Page 38: Strings Methods Slides Java Aplus

©A+ Computer Science www.apluscompsci.com 38

Page 39: Strings Methods Slides Java Aplus

©A+ Computer Science www.apluscompsci.com 39

Page 40: Strings Methods Slides Java Aplus

©A+ Computer Science www.apluscompsci.com 40

Page 41: Strings Methods Slides Java Aplus

©A+ Computer Science www.apluscompsci.com 41

Page 42: Strings Methods Slides Java Aplus

©A+ Computer Science www.apluscompsci.com 42