Java Characters
Java Characters
Outline
11.1 Introduction
11.2 Fundamentals of Characters and Strings
11.3 Class String
11.3.1 String Constructors
11.3.2 String Methods length, charAt and getChars
11.3.3 Comparing Strings
11.3.4 Locating Characters and Substrings in Strings
11.3.5 Extracting Substrings from Strings
11.3.6 Concatenating Strings
11.3.7 Miscellaneous String Methods
11.3.8 String Method valueOf
11.4 Class StringBuffer
11.4.1 StringBuffer Constructors
11.4.2 StringBuffer Methods length, capacity,
setLength and ensureCapacity
11.4.3 StringBuffer Methods charAt, setCharAt,
getChars and reverse
11.4.4 StringBuffer append Methods
11.4.5 StringBuffer Insertion and Deletion Methods
1.6 Class StringTokenizer
• Class String
– Provides nine constructors
StringIndexMeth
ods.java
• Method concat
– Concatenate two String objects
• Class StringBuffer
– When String object is created, its contents cannot change
– Used for creating and manipulating dynamic string data
• i.e., modifiable Strings
– Can store characters based on capacity
• Capacity expands dynamically to handle additional characters
– Uses operators + and += for String concatenation
• Method length
– Return StringBuffer length
• Method capacity
– Return StringBuffer capacity
• Method setLength
– Increase or decrease StringBuffer length
• Method ensureCapacity
– Set StringBuffer capacity
– Guarantee that StringBuffer has minimum capacity
Only 10 characters
from
StringBuffer are
printed
• Method append
– Allow data values to be added to StringBuffer
StringBufferIns
ert.java
• Tokenizer
– Partition String into individual substrings
– Use delimiter
– Java offers java.util.StringTokenizer