Self-Assessment Exercises
Chapter 16:
Files, File Parsing, and Strings
1.
Suppose you have declared the string
myString
with the statement
final myString = "\"Hello There\"";
Which of the following expressions returns
‘H’
?
a.
myString[1]
b.
myString.charAt(1)
c.
myString.indexOf(1)
d.
myString.indexOf(‘H’)
2.
Using
myString
from the previous question, which of the following expressions evaluates to a string of length 6?
a.
myString.length();
b.
myString.substring(indexOf("T"));
c.
myString.substring(indexOf("T"));
d.
myString.substring(indexOf(" There"));
3.
Suppose you have two strings named
stringOne
and
stringTwo
. Which of the following expressions should be used to test if they have equal values?
a.
stringOne == stringTwo
b.
stringOne.equal(stringTwo)
c.
stringOne.equals(stringTwo)
d.
equal(stringOne, stringTwo)
4.
Which of the following is NOT true for Java file input/output?
a.
The model for working with streams is to start with a stream of characters.
b.
The transfer of input data can be made much more efficient by creating a buffered reader.
c.
Java applets are typically not allowed to access files on the user’s computer for security reasons.
d.
IOException
errors can occur.
5.
Which of the following classes is used to parse a string?
a.
String
b.
StringBuffer
c.
StringParser
d.
StringTokenizer