String Processing Flashcards

1
Q

Which deprecated class splits a String into elements but does not support enhanced for iteration?

A

StringTokenizer

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

In a regular expression, which character indicates an optional subpattern that can match only once?

A

?

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does the format parameter %s specify?

A

String conversion

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

In a regular expression, which metacharacter specifies a word boundary?

A

\b

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

In a regular expression, which metacharacter specifies an upper/lowercase letter or digit?

A

\w

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

In a regular expression, which character indicates zero or more subpattern match?

A

*

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

In a format string, what does the % character specify?

A

The beginning of a format parameter

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

In a String, which character is required to escape the initial backslash for Java?

A

\

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

When using manipulation methods of the StringBuffer and StringBuilder class, how is the underlying String affected?

A

The underlying String is modified.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What does the format parameter %b specify?

A

Boolean conversion

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

When using the format parameter %b, which two values will convert to false?

A

false, null

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Which String method accepts a regular expression and replacement string for each match, and returns a manipulated string?

A

replaceAll

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Which Scanner method accepts a regular expression and returns the next match found in the source line?

A

findInLine

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

In a format string, what does the $ character specify?

A

the end of an argument location

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What does “3” in format string %3.4s represent

A

Minimum number of characters to output.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What does “4” in format string %3.4s represent

A

The number of characters of the argument string to output.

17
Q

What would the following printf statement output:

System.out.printf(““,1234);

A

>

 1234
18
Q

What would the following printf statement output:

System.out.printf(““,1234);

A

> 1234

19
Q

What does format flag “-“ do?

System.out.printf(““,1234);

A

Left justifies (default is right justify)

20
Q

What does format flag “+” do?

A

Outputs a plus or minus sign for a numerical value.

21
Q

What would the following statement output?

System.out.printf(““,1);

A

> +000000001

22
Q

Can more than one format flag be used in a format statement?

A

Yes,

System.out.printf(“>%0+10d+000000001

23
Q

What is the output of this statement?

System.out.printf(““,1);

A

java.util.IllegalFormatFlagsException

Using “0” for zero fill and “-“ for left jistify together is not valid.

24
Q

What does format flag “0” do?

A

forces numerical values to be zero-padded (default is blank padding).

25
Q

What does format flag “,” do?

A

Comma grouping seperator for numbers > 1000

System.out.printf(“>%0+,10d,1);

26
Q

Is System.out.printf(““,1000); a valid statement and if yes what will it output?

A

> +00001,000

27
Q

What flag is used to output a minus character for negative numbers and a space for positive numbers?

A

Space as in

System.out.printf(“>% ,10d,-1001);

28
Q

Consider:
String nullString = null;
String ten = nullString.valueOf(10); // Line 2

Will Line 2 generate a null pointer exception?

A

No! Because valueOf is a static method so the referencetype is used not the object type. The string ten will be set to “10”.

29
Q

What are the String static methods?

A

valueOf, format, copyValueOf

30
Q

Is this following valid?

aString.format(“%s%n”,aString);

A

Yes! It will output the string followed by a