String Processing Flashcards
Which deprecated class splits a String into elements but does not support enhanced for iteration?
StringTokenizer
In a regular expression, which character indicates an optional subpattern that can match only once?
?
What does the format parameter %s specify?
String conversion
In a regular expression, which metacharacter specifies a word boundary?
\b
In a regular expression, which metacharacter specifies an upper/lowercase letter or digit?
\w
In a regular expression, which character indicates zero or more subpattern match?
*
In a format string, what does the % character specify?
The beginning of a format parameter
In a String, which character is required to escape the initial backslash for Java?
\
When using manipulation methods of the StringBuffer and StringBuilder class, how is the underlying String affected?
The underlying String is modified.
What does the format parameter %b specify?
Boolean conversion
When using the format parameter %b, which two values will convert to false?
false, null
Which String method accepts a regular expression and replacement string for each match, and returns a manipulated string?
replaceAll
Which Scanner method accepts a regular expression and returns the next match found in the source line?
findInLine
In a format string, what does the $ character specify?
the end of an argument location
What does “3” in format string %3.4s represent
Minimum number of characters to output.
What does “4” in format string %3.4s represent
The number of characters of the argument string to output.
What would the following printf statement output:
System.out.printf(“<%10.4s>”,1234);
>
1234<
What would the following printf statement output:
System.out.printf(“<%-10.4s>”,1234);
> 1234 <
What does format flag “-“ do?
System.out.printf(““,1234);
Left justifies (default is right justify)
What does format flag “+” do?
Outputs a plus or minus sign for a numerical value.
What would the following statement output?
System.out.printf(“<%0+10d>”,1);
> +000000001<
Can more than one format flag be used in a format statement?
Yes,
System.out.printf(“>%0+10d+000000001<
What is the output of this statement?
System.out.printf(“<%0-10d>”,1);
java.util.IllegalFormatFlagsException
Using “0” for zero fill and “-“ for left jistify together is not valid.
What does format flag “0” do?
forces numerical values to be zero-padded (default is blank padding).
What does format flag “,” do?
Comma grouping seperator for numbers > 1000
System.out.printf(“>%0+,10d,1);
Is System.out.printf(“<%0+,10d>”,1000); a valid statement and if yes what will it output?
> +00001,000<
What flag is used to output a minus character for negative numbers and a space for positive numbers?
Space as in
System.out.printf(“>% ,10d,-1001);
Consider:
String nullString = null;
String ten = nullString.valueOf(10); // Line 2
Will Line 2 generate a null pointer exception?
No! Because valueOf is a static method so the referencetype is used not the object type. The string ten will be set to “10”.
What are the String static methods?
valueOf, format, copyValueOf
Is this following valid?
aString.format(“%s%n”,aString);
Yes! It will output the string followed by a