MSIS 655 Advanced Business Applications Programming Week 8
MSIS 655 Advanced Business Applications Programming Week 8 Strings and Characters (Ch. 29) 12/27/2021 8. 1
Introduction String and character processing n n Class java. lang. String. Buffer Class java. lang. Character Class java. util. String. Tokenizer String n n Series of characters treated as single unit May include letters, digits, special characters. Object of class String literals 12/27/2021 2
String Constructors Fig. 29. 1 demonstrates four constructors n n No-argument constructor One-argument constructor w A String object n One-argument constructor w A char array n Three-argument constructor w A char array w An integer specifies the starting position w An integer specifies the number of characters to access 12/27/2021 3
String Methods (Fig. 29. 2) Method length n Determine the length of a String w Like arrays, Strings always “know” their size w Unlike array, Strings do not have length instance variable Method char. At n Get character at specific location in String Method get. Chars n Get entire set of characters in String 12/27/2021 4
Comparing Strings (Fig. 29. 3) Comparing String objects n n Method equals. Ignore. Case Method compare. To Method region. Matches 12/27/2021 5
Miscellaneous String Methods starts. With / ends. With Methods index. Of / last. Index. Of Method substring Method concat Methods replace / to. Upper. Case / to. Lower. Case / trim Method value. Of 12/27/2021 6
Class String. Buffer n n When String object is created, its contents cannot change Used for creating and manipulating dynamic string data w i. e. , modifiable Strings n Can store characters based on capacity w Capacity expands dynamically to handle additional characters n Uses operators + and += for String concatenation 12/27/2021 7
Class Character Treat primitive variables as objects n Type wrapper classes w w w w 12/27/2021 Boolean Character Double Float Byte Short Integer Long 8
Class String. Tokenizer n n Partition String into individual substrings Use delimiter w Typically whitespace characters (space, tab, newline, etc) n Java offers java. util. String. Tokenizer 12/27/2021 9
Lab activities (Week 8) Exercises (pp. 1392 -93) 29. 5, 29. 7, 29. 8, Advanced: 29. 19 12/27/2021 10
- Slides: 10