SlideShare a Scribd company logo
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 into
strings to affect the
display
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
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.
16
Comparing Strings
Strings can be compared to see if they
are equal:
equals() method is case sensitive
equalsIgnoreCase() method ignores
case
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()
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.
16
Creating Files forReading
and Writing
Use FileInputStream class for reading
from files
Use FileWriter class for writing to files
(uses internal FileOutputStream object)
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
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

More Related Content

PPTX
Java Tutorial Lab 7
PPTX
Java Tutorial Lab 6
PPTX
Java Tutorial Lab 2
PPTX
Java Tutorial Lab 9
PPT
List and iterator
PPTX
Module 7 : Arrays
PDF
Introducing Pattern Matching in Scala
Java Tutorial Lab 7
Java Tutorial Lab 6
Java Tutorial Lab 2
Java Tutorial Lab 9
List and iterator
Module 7 : Arrays
Introducing Pattern Matching in Scala

What's hot (15)

PPTX
Java Tutorial Lab 8
PPTX
An Introduction To Python - Tables, List Algorithms
PDF
An Introduction to the C++ Standard Library
PPTX
Arrays
PPTX
Collections (1)
PDF
Java Regular Expression PART I
PPTX
Data Analysis packages
PPTX
Lists in Python
PDF
Array linear data_structure_2 (1)
PPT
Presentation of array
PPTX
Text and Numbers (Data Types)in PHP
PDF
STL in C++
PPT
List data structure
PDF
Python - Lecture 11
Java Tutorial Lab 8
An Introduction To Python - Tables, List Algorithms
An Introduction to the C++ Standard Library
Arrays
Collections (1)
Java Regular Expression PART I
Data Analysis packages
Lists in Python
Array linear data_structure_2 (1)
Presentation of array
Text and Numbers (Data Types)in PHP
STL in C++
List data structure
Python - Lecture 11
Ad

Viewers also liked (8)

PPT
Chapter 12
PPT
Chapter 15
PPT
Enterprise Skills
PPT
Chapter 14
PPT
Chapter 17
PPT
Chapter 18
PPT
Key enterprise skills
PPT
Chapter 11
Chapter 12
Chapter 15
Enterprise Skills
Chapter 14
Chapter 17
Chapter 18
Key enterprise skills
Chapter 11
Ad

Similar to Chapter 16 (20)

PPTX
PDF
PPS
String and string buffer
PPTX
13string in c#
PPTX
stringstringbuilderstringbuffer-190830060142.pptx
PPT
Strings Arrays
PPTX
String, string builder, string buffer
PPT
M C6java7
PPT
LiangChapter4 Unicode , ASCII Code .ppt
PDF
ppt notes python language operators and data
PDF
STRINGS IN C MRS.SOWMYA JYOTHI.pdf
PPT
07slide
PPTX
Computer programming 2 Lesson 12
PPTX
String handling
PPT
String handling session 5
PPTX
package
PPTX
Strings in Java
PPTX
OCA Java SE 8 Exam Chapter 3 Core Java APIs
PDF
Airoli_Grade 10_CompApp_PP000000000000000000000000000000000000000000T_Charact...
PPTX
String and StringBufferString and StringBuffer e examples.pptx
String and string buffer
13string in c#
stringstringbuilderstringbuffer-190830060142.pptx
Strings Arrays
String, string builder, string buffer
M C6java7
LiangChapter4 Unicode , ASCII Code .ppt
ppt notes python language operators and data
STRINGS IN C MRS.SOWMYA JYOTHI.pdf
07slide
Computer programming 2 Lesson 12
String handling
String handling session 5
package
Strings in Java
OCA Java SE 8 Exam Chapter 3 Core Java APIs
Airoli_Grade 10_CompApp_PP000000000000000000000000000000000000000000T_Charact...
String and StringBufferString and StringBuffer e examples.pptx

More from Graham Royce (20)

PPT
Chapter 13
PPT
Chapter 10
PPT
Chapter 09
PPT
Chapter 08
PPT
Chapter 07
PPT
Chapter 06
PPT
Chapter 05
PPT
Chapter 04
PPT
Chapter 03
PPT
Chapter 02
PPT
Chapter 01
PPT
13 java in oracle
PPT
Java tut1 Coderdojo Cahersiveen
PPT
My 3 min pitch pack
PPTX
Things to do
PPTX
House in order
PPT
Blank 10 all you need
PPTX
PPT
Idea's1 only
PPT
New frontiers motivation
Chapter 13
Chapter 10
Chapter 09
Chapter 08
Chapter 07
Chapter 06
Chapter 05
Chapter 04
Chapter 03
Chapter 02
Chapter 01
13 java in oracle
Java tut1 Coderdojo Cahersiveen
My 3 min pitch pack
Things to do
House in order
Blank 10 all you need
Idea's1 only
New frontiers motivation

Recently uploaded (20)

DOC
NSCAD毕业证学历认证,温哥华岛大学毕业证国外证书制作申请
PPTX
the Honda_ASIMO_Presentation_Updated.pptx
PPT
business model and some other things that
PPTX
Other Dance Forms - G10 MAPEH Reporting.pptx
PDF
A New Kind of Director for a New Kind of World Why Enzo Zelocchi Matters More...
PPTX
Understanding Colour Prediction Games – Explained Simply
PDF
Songlyrics.net-website for lyrics song download
PPTX
providenetworksystemadministration.pptxhnnhgcbdjckk
PPTX
E8 ssssssssssssssssssssssssssssssssssQ1 0101 PS.pptx
PPTX
What Makes an Entertainment App Addictive?
PDF
MAGNET STORY- Coaster Sequence (Rough Version 2).pdf
PDF
oppenheimer and the story of the atomic bomb
PPTX
The story of Nomuzi and the way she was living
PDF
Rakshabandhan – Celebrating the Bond of Siblings - by Meenakshi Khakat
PDF
My Oxford Year- A Love Story Set in the Halls of Oxford
PDF
Rare Big Band Arrangers Who Revolutionized Big Band Music in USA.pdf
PPTX
the-solar-system.pptxxxxxxxxxxxxxxxxxxxx
PDF
Ct.pdffffffffffffffffffffffffffffffffffff
PPTX
genderandsexuality.pptxjjjjjjjjjjjjjjjjjjjj
PDF
Gess1025.pdfdadaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
NSCAD毕业证学历认证,温哥华岛大学毕业证国外证书制作申请
the Honda_ASIMO_Presentation_Updated.pptx
business model and some other things that
Other Dance Forms - G10 MAPEH Reporting.pptx
A New Kind of Director for a New Kind of World Why Enzo Zelocchi Matters More...
Understanding Colour Prediction Games – Explained Simply
Songlyrics.net-website for lyrics song download
providenetworksystemadministration.pptxhnnhgcbdjckk
E8 ssssssssssssssssssssssssssssssssssQ1 0101 PS.pptx
What Makes an Entertainment App Addictive?
MAGNET STORY- Coaster Sequence (Rough Version 2).pdf
oppenheimer and the story of the atomic bomb
The story of Nomuzi and the way she was living
Rakshabandhan – Celebrating the Bond of Siblings - by Meenakshi Khakat
My Oxford Year- A Love Story Set in the Halls of Oxford
Rare Big Band Arrangers Who Revolutionized Big Band Music in USA.pdf
the-solar-system.pptxxxxxxxxxxxxxxxxxxxx
Ct.pdffffffffffffffffffffffffffffffffffff
genderandsexuality.pptxjjjjjjjjjjjjjjjjjjjj
Gess1025.pdfdadaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

Chapter 16

  • 1. Files, File Parsing, and Strings Chapter 16
  • 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. 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. 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. 16 Comparing Strings Strings can be compared to see if they are equal: equals() method is case sensitive equalsIgnoreCase() method ignores case
  • 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. 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. 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. 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. 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