Quiz on StringBuffers and StringTokenizers

This is a practice quiz. The results are not recorded anywhere and do not affect your grade. The questions on this quiz might not appear in any quiz or test that does count toward your grade.

Instructions: For each question, choose the single best answer. Make your choice by clicking on its button. You can change your answers at any time. When the quiz is graded, the correct answers will appear in the box after each question.


1. Which phrase best describes a String object after it has been constructed?

a.    Changeable.
b.    Write Only.
c.    Read Only.
d.    Inaccessible

Correct Answer Is:


2. After a StringBuffer has been constructed, how many characters may be added to it?

a.    No more after it has been constructed.
b.    Only as many as the original capacity.
c.    As many as needed; it will grow in size if necessary.
d.    A new StringBuffer must be constructed each time characters are added.

Correct Answer Is:


3. Which of the following methods does the StringBuffer class NOT have?

a.    append( int i )
b.    charAt( int index )
c.    length()
d.    delete( int index )

Correct Answer Is:


4. You wish to compare the contents of two StringBuffer objects. How should this be done?

a.    Use the == operator.
b.    Use the equals() method of StringBuffer.
c.    Construct a String object from each StringBuffer and use their equals() method.
d.    Do a character-by-character comparison using charAt() and ==.

Correct Answer Is:


5. What is a token.

a.    A token is any character that may be used as punctuation.
b.    A token is a group of characters that means something in a particular context.
c.    A token is a type of expression.
d.    A token is a group of digits.

Correct Answer Is:


6. What is a delimiter?

a.    A delimiter is a character that separates the tokens in a string.
b.    A delimiter is any character that may be part of a token.
c.    A delimiter is the last character of a string.
d.    A delimiter is any character that may be part of a number.

Correct Answer Is:


7. What does this code write:

StringTokenizer stuff = new StringTokenizer( "abc,def,ghi" );
System.out.println( stuff.nextToken() );
a.    abc,def,ghi
b.    abc
c.    abc,
d.    abc def ghi

Correct Answer Is:


8. What does this code write:

StringTokenizer stuff = new StringTokenizer( "abc,def,ghi", "," );
System.out.println( stuff.nextToken() );
a.    abc,def,ghi
b.    abc
c.    abc,
d.    ,

Correct Answer Is:


9. What does this code write:

StringTokenizer stuff = new StringTokenizer( "abc+def+ghi", "+", true );
System.out.println( stuff.nextToken() );
System.out.println( stuff.nextToken() );
a.   
abc
b.   
abc +def
c.   
abc
def
d.   
abc
+

Correct Answer Is:


10. What does this code write:

StringTokenizer stuff = new StringTokenizer( "abc def+ghi", "+");
System.out.println( stuff.nextToken() );
System.out.println( stuff.nextToken() );

a.   
abc
def
b.   
abc def
ghi
c.   
abc def
+
d.   
abc def
+ghi

Correct Answer Is:


The number you got right:       Percent Correct:       Letter Grade:   


Click here (If you have just returned here from another page, or have re-loaded this page, you will need to click again on each of your choices for the grading program to work correctly. You may want to press the "shift key" while clicking on reload to clear the old answers.)