lecture5 - PIC 20A Lecture 5: Strings and Scanners Strings...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
PIC 20A Lecture 5: Strings and Scanners
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Strings • sequences of characters • String is a class in Java • Java also has String literal values which are enclosed in quotation marks eg “apple” • values (object or literal) can be concatenated by the + operator
Background image of page 2
More on Strings • first index of a character in a string is 0 • number of characters in a string is called the length of the string • String objects – have a length() method –are immutable - they cannot be modified after they are created
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Even More on Strings • concatenating a String with any object results in an implicit call to the Object 's toString method. eg Rectangle r = new Rectangle(0,0,0,0); //The following are equivalent: System.out.println(r); System.out.println(r.toString());
Background image of page 4
• because a reference cannot be used to modify a String , it is safe to have may references to one String object in a Java program. • String
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 18

lecture5 - PIC 20A Lecture 5: Strings and Scanners Strings...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online