{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

ch03-3Str - UsingObjects Ch.3.3Strings...

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

View Full Document Right Arrow Icon
1 Building Java Programs Using Objects Ch. 3.3 Strings These lecture notes are copyright (C) Marty Stepp and Stuart Reges, 2007.  They may not be  rehosted, sold, or modified without expressed permission from the authors.  All rights reserved.
Background image of page 1

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

View Full Document Right Arrow Icon
2 String objects suggested reading: 3.3, 4.2
Background image of page 2
3 String objects string : A sequence of text characters. One of the most common types of objects. In Java, strings are represented as objects of class  String . String  variables can be declared and assigned, just like  primitive values: String <name> = " <text> "; String <name> = <expression that produces a String> ; Unlike most other objects, a  String  is not created with  new . Examples: String name = "Marla Singer"; int x = 3, y = 5; String point = "(" + x + ", " + y + ")";
Background image of page 3

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

View Full Document Right Arrow Icon
4 Indexes The characters in a  String  are each internally numbered with  an  index , starting with 0: Example: String name = "P. Diddy"; Individual characters are represented inside the  String  by  values of a primitive type called  char . Literal  char  values are surrounded with apostrophe (single-quote)  marks, such as  'a'  or  '4' . An escape sequence can be represented as a  char , such as  '\n'   (new-line character) or  '\''  (apostrophe). index 0 1 2 3 4 5 6 7 character 'P' '.' ' ' 'D' 'i' 'd' 'd' 'y'
Background image of page 4
5 String methods Useful methods of each  String  object: These methods are called using the dot notation:
Background image of page 5

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

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

{[ snackBarMessage ]}