0% found this document useful (0 votes)
47 views3 pages

Sapt 5 String Processing Quizz Sect 3 L3

This document provides a quiz on string processing and regular expressions in Java with 10 multiple choice questions. It covers topics such as parsing strings, the StringBuilder class, regular expression syntax like special characters and quantifiers, using Pattern and Matcher classes, and benefits of using groups in regular expressions. Correct answers are provided for each question.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views3 pages

Sapt 5 String Processing Quizz Sect 3 L3

This document provides a quiz on string processing and regular expressions in Java with 10 multiple choice questions. It covers topics such as parsing strings, the StringBuilder class, regular expression syntax like special characters and quantifiers, using Pattern and Matcher classes, and benefits of using groups in regular expressions. Correct answers are provided for each question.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

Section 3 String Processing Quizz

Section 1

1. Which of the following are true about parsing a String?

(Choose all correct answers)

It is a way of dividing a string into a set of sub-strings. (*)


It is not possible to parse a string using regular expressions.
It is possible to use a for loop to parse a string. (*)
It is possible to use the String.split() method to parse a string. (*)

Correct

2. Which of the following correctly defines a StringBuilder?

A method that adds characters to a string.


A class inside the java.util.regex package.
A class that represents a string-like object. (*)
There is no such thing as a StringBuilder in Java.

Correct

3. Identify the method, of those listed below, that is not available to both StringBuilders and Strings?

length()
delete(int start, int end) (*)
charAt(int index)
indexOf(String str)

Correct

4. A regular expression is a character or a sequence of characters that represent a string or multiple


strings.
True or false?

True (*)
False

Correct

5. What does the dot (.) represent in regular expressions?

An indication for one or more occurrences of the preceding character.


A match for any character. (*)
A range specified between brackets that allows variability of a character.
Nothing, it is merely a dot.

Correct
6. In a regular expression, {x} and {x,} represent the same thing, that the preceding character may
occur x or more times to create a match.
True or false?

True
False (*)

Correct

7. Your teacher asks you to write a segment of code that returns true if String str contains zero or one
character(s) and false otherwise. Which of the following code segments completes this task?

(Choose all correct answers)

return str.matches(".?"); (*)


return str.contains(".");
if( str.length() == 0 || str.length() == 1)
{ return true;}
return false; (*)
return str.matches("[a-z]*");

Incorrect. Refer to Section 3 Lesson 3.

8. Which of the following correctly defines Pattern?

A regular expression symbol that represents any character.


A class in the java.util.regex package that stores matches.
A method of dividing a string into a set of sub-strings.
A class in the java.util.regex package that stores the format of a regular expression. (*)

Correct

9. Which of the following correctly initializes a Matcher m for Pattern p and String str?

Matcher m = p.matcher(str); (*)


Matcher m = new Matcher(p,str);
Matcher m = str.matcher(p);
Matcher m = new Matcher();

Correct

10One benefit to using groups with regular expressions is that you can segment a matching string and
. recall the segments (or groups) later in your program.
True or false?

True (*)
False

Correct

Page 1 of 1

You might also like