Langsung ke konten utama

Section 3 String processing Oracle Java Programming

Section 3 String processing
                (Answer all questions in this section)

1.            Which of the following are true about parsing a String?   Mark for Review
                                                (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. (*)

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.

3.            Identify the method, of those listed below, that is not available to both StringBuilders and Strings?            Mark for Review
                length()
                delete(int start, int end) (*)
                charAt(int index)
                indexOf(String str)

4.            A regular expression is a character or a sequence of characters that represent a string or multiple strings.
True or false?    Mark for Review
                True (*)
                False

5.            What does the dot (.) represent in regular expressions? Mark for Review
(1) Points
                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.

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?    Mark for Review
                True
                False (*)

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?       Mark for Review
                                                (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]*");

8.            Which of the following correctly defines Pattern?             Mark for Review
                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. (*)

9.            Which of the following correctly initializes a Matcher m for Pattern p and String str?         Mark for Review
                Matcher m = p.matcher(str); (*)
                Matcher m = new Matcher(p,str);
                Matcher m = str.matcher(p);
                Matcher m = new Matcher();

10.          One 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?    Mark for Review
                True (*)

                False

Komentar