Chapter5 String
Chapter5 String
CHAPTER 5 STRINGS
Prepared by Mr. KAY HENG
2
Strings p.257
• Introduction
• The String class
• The Character class
• The StringBuffer class
3
Introduction
• A string is sequence (series) of characters.
• A string is NOT an array of characters.
E.g. in C/C++: char s[20];
• In Java, A String is an object.
• Java has 3 String classes:
• String
• StringBuffer
• StringTokenizer
4
• Lab time:
• Example 7.1 Checking Palindromes p.266
10
THE CHARACTER
CLASS
11
Lab: Exercise 1
• Count the number of words in a given String
Example:
Input: National Polytechnic Institute of Cambodia
Output: Word Count: 5 words
17
Lab: Exercise 2
• On page 285, Section 7.4 The StringBuffer Class