Files, File Parsing,
and Strings
Chapter 16
16
About Strings
String is a class, not
an intrinsic type.
Escape sequences:
Backslash ()
followed by a
character
Embedded...
16
Working with Strings
Concatenation
“Add” two strings together using +
operator
Use the += operator with String objects
...
16
Locating Characters in Strings
Locating Characters:
indexOf() method returns index of a
specific character.
Overloaded ...
16
Comparing Strings
Strings can be compared to see if they
are equal:
equals() method is case sensitive
equalsIgnoreCase(...
16
The StringBuffer Class
Java strings are immutable. Use
StringBuffer object when you need
to modify a string of characte...
16
Reading Files
The stream object represents bytes
moving from source to destination.
InputStreamReader works with
indivi...
16
Creating Files forReading
and Writing
Use FileInputStream class for reading
from files
Use FileWriter class for writing...
16
Parsing and Tokens
StringTokenizer class breaks a
string into tokens.
Uses either default rules or user-provided
delimi...
16
Using StreamTokenizer
StreamTokenizer class is more flexible
than StringTokenizer.
Allows you to establish table of “ru...
Upcoming SlideShare
Loading in …5
×

Chapter 16

249 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
249
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Chapter 16

  1. 1. Files, File Parsing, and Strings Chapter 16
  2. 2. 16 About Strings String is a class, not an intrinsic type. Escape sequences: Backslash () followed by a character Embedded into strings to affect the display
  3. 3. 16 Working with Strings Concatenation “Add” two strings together using + operator Use the += operator with String objects Examining Strings length() returns number of characters charAt() returns character at specific index
  4. 4. 16 Locating Characters in Strings Locating Characters: indexOf() method returns index of a specific character. Overloaded to return index of a character after a certain starting index substring() method extracts characters from a string.
  5. 5. 16 Comparing Strings Strings can be compared to see if they are equal: equals() method is case sensitive equalsIgnoreCase() method ignores case
  6. 6. 16 The StringBuffer Class Java strings are immutable. Use StringBuffer object when you need to modify a string of characters. Includes methods to: Set character at specific index: setCharAt() Append characters: append() Insert characters at a specific index: insert() Reverse the characters: reverse()
  7. 7. 16 Reading Files The stream object represents bytes moving from source to destination. InputStreamReader works with individual characters. BufferedReader works with bytes or lines of character data at a time.
  8. 8. 16 Creating Files forReading and Writing Use FileInputStream class for reading from files Use FileWriter class for writing to files (uses internal FileOutputStream object)
  9. 9. 16 Parsing and Tokens StringTokenizer class breaks a string into tokens. Uses either default rules or user-provided delimiters to determine tokens Use hasMoreTokens() to determine if StringTokenizer contains more tokens Use nextToken() to return next token
  10. 10. 16 Using StreamTokenizer StreamTokenizer class is more flexible than StringTokenizer. Allows you to establish table of “rules” Uses flags to establish various states to use with table of rules Commonly used constants: TT_EOF indicates the end of stream TT_EOL indicates the end of line TT_NUMBER indicates a number token has been read TT_WORD indicates a word token has been read

×