Deck 8: Text Processing and Wrapper Classes

Full screen (f)
exit full mode
Question
The StringBuilder class's insert method allows you to insert into the calling object's string

A) a char array.
B) a primitive type.
C) a String object.
D) All of the above
Use Space or
up arrow
down arrow
to flip the card.
Question
Which of the following statements converts an int variable named number to a string and stores the value in the String object variable named str?

A) String str = Integer.toString(number);
B) String str = number.Integer.toString(str);
C) String str = integer(number);
D) String str = integer.toString(number);
Question
What will be displayed after the following code is executed?
String str = "abc456";
For (int i = 0; i < str.length(); i++)
{
Char chr = str.charAt(i);
If (!Character.isLetter(chr))
System.out.print(Character.toUpperCase(chr));
}

A) ABC
B) ABC456
C) 456
D) abc456
Question
Which of the following statements is not true about the following code?
StringBuilder strb =
New StringBuilder("Total number of parts: ");
Strb.insert(23, 32);

A) The starting position for the insert is 23.
B) strb is a StringBuilder type object.
C) The ending position for the insert is 32.
D) The literal number 32 will be inserted into the string.
Question
Which of the following statements converts a String object variable named str to an int and stores the value in the variable x?

A) int x = Integer.integer(str);
B) int x = str;
C) int x = Integer.parseInteger(str);
D) int x = Integer.parseInt(str);
Question
What will be displayed after the following code is executed?
String str = "RSTUVWXYZ";
System.out.println(str.charAt(5));

A) W
B) X
C) V
D) U
Question
What will be displayed after the following statements are executed?
StringBuilder strb =
New StringBuilder("We have lived in Chicago, Trenton, and Atlanta.");
Strb.replace(17, 24, "Tampa");
System.out.println(strb);

A) We have lived in Tampa, Trenton, and Atlanta.
B) We have lived in Chicago, Trenton, and Tampa.
C) We have lived in Chicago, Tampaon, and Atlanta.
D) We have lived in Chicago, Tampa, and Atlanta.
Question
Which of the following import statements is required to use the StringTokenizer class?

A) import java.util.Scanner
B) import java.text.DecimalFormat;
C) import java.util.StringTokenizer;
D) import javax.swing.JOptionPane;
Question
What will be the value of position after the following code is executed?
Int position;
String str = "The cow jumped over the moon.";
Position = str.lastIndexOf("ov", 14);

A) 14
B) 1
C) 0
D) -1
Question
A series of words or other items of data separated by spaces or other characters are known as

A) strings.
B) tokens.
C) delimiters.
D) captions.
Question
Which of the following are used as delimiters if the StringTokenizer class's constructor is called and a reference to a String object is passed as the only argument?

A) space
B) tab
C) newline
D) All of the above
Question
What will be the tokens in the following statement?
StringTokenizer st =
New StringTokenizer("9-14-2014", "-", true);

A) 9, 14, and 2014
B) 9, 14, 2014, and -
C) -
D) None of the above
Question
Which of the following statements converts a double variable named tax to a string and stores the value in the String object variable named str?

A) String str = Double.toString(tax);
B) String str = double(tax);
C) String str = double.toString(tax);
D) String str = tax.Double.toString(str);
Question
The Character wrapper class provides numerous methods for

A) converting objects to primitive data types.
B) testing and converting character data.
C) testing and converting numeric literals.
D) performing operations with named constants.
Question
Which of the following statements will display the maximum value that a double can hold?

A) System.out.println(Double.MAX_VALUE);
B) System.out.println(Double.MAXIMUM_VALUE);
C) System.out.println(Double.MAX_VAL);
D) System.out.println((MAX_VALUE));
Question
What will be displayed after the following code has been executed?
String str1 = "The quick brown fox jumped over the lazy dog."; String str2 = str1.substring(20, 26);
System.out.println(str2);

A) n fox
B) jumped
C) lazy d
D) x jump
Question
For the following code, how many times would the while loop execute?
StringTokenizer st =
New StringTokenizer("Java programming is fun!");
While (st.hasMoreTokens())
System.out.println(st.nextToken());

A) 7
B) 4
C) 5
D) 1
Question
In the following statement, what data type must recField be?
Str)getChars(5, 10, recField, 0);

A) int
B) char[]
C) char
D) String
Question
What will be displayed after the following code has been executed?
Boolean matches;
String str1 = "The cow jumped over the moon.";
String str2 = "moon";
Matches = str1.endsWith(str2);
System.out.println(matches);

A) true
B) moon
C) false
D) The cow
Question
The ________ method returns a copy of the calling String object, in which all leading and trailing whitespace characters have been deleted.

A) remove
B) trim
C) compress
D) concat
Question
When working with the String and StringBuilder class's getChars method, the character at the start position is included in the substring, but the character at the end position is not included.
Question
Any ________ argument passed to the Character class's toLowerCase method or toUpperCase method is returned as it is.

A) nonletter
B) char
C) string
D) static
Question
What will be displayed after the following statements are executed?
String str = "red$green&blue#orange";
String[] tokens = str.split("[$&#]");
For (String s : tokens)
System.out.print(s + " ");

A) red green blue orange
B) Red $ green & blue # orange
C) $ & #
D) red [$&#] green [$&#] blue [$&#] orange
Question
StringBuilder objects are not immutable.
Question
You can concatenate String objects by

A) using the concat or trim methods.
B) using the concat method or the + operator.
C) using the concatenate or join methods.
D) using the concatenate method or the + operator.
Question
The String class's regionMatches method performs a case-insensitive comparison.
Question
The term ________ commonly is used to refer to a string that is part of another string.

A) nested string
B) literal
C) substring
D) delimiter
Question
A wrapper class is a class that is "wrapped around" a primitive data type and allows you to create objects instead of variables.
Question
If a string has more than one character used as a delimiter, we must write a loop to determine the tokens, one for each delimiter character.
Question
What will be the value of position after the following code is executed?
Int position;
String str = "The cow jumped over the moon.";
Position = str.indexOf("ov");

A) 14
B) 15
C) 18
D) 17
Question
You will cause an off-by-one error, when working with a character position within a string, if you think of the first position in a string as 1.
Question
Most of the String comparison methods are case sensitive.
Question
The ________ class is the wrapper class for the char data type.

A) StringBuilder
B) Integer
C) Character
D) String
Question
Trying to extract more tokens than exist from a StringTokenizer object will cause an error.
Question
Which of the following import statements is required to use the Character wrapper class?

A) import java.String
B) import java.lang.Char
C) import java.Char
D) No import statement is needed
Question
You cannot assign a value to a wrapper class object.
Question
What will be displayed after the following statements are executed?
StringBuilder strb = new StringBuilder(12);
Strb.append("The cow ");
Strb.append("jumped over the ");
Strb.append("moon.");
System.out.println(strb);

A) The cow jumped over the moon.
B) The cow jumped over the
Moon.
C) The cow jump
D) 12The cow jumped over the moon.
Question
The String class's valueOf method accepts a string representation as an argument and returns its equivalent integer value.
Question
The String class's ________ method accepts a value of any primitive data type as its argument and returns a string representation of the value.

A) trim
B) getChar
C) toString
D) valueOf
Question
In the ________ file format, when the data in a spreadsheet is exported, each row is written to a line, and the values in the cells are separated by commas.

A) comma separated value
B) extensible markup language
C) excel binary
D) data interchange
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/40
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 8: Text Processing and Wrapper Classes
1
The StringBuilder class's insert method allows you to insert into the calling object's string

A) a char array.
B) a primitive type.
C) a String object.
D) All of the above
D
2
Which of the following statements converts an int variable named number to a string and stores the value in the String object variable named str?

A) String str = Integer.toString(number);
B) String str = number.Integer.toString(str);
C) String str = integer(number);
D) String str = integer.toString(number);
A
3
What will be displayed after the following code is executed?
String str = "abc456";
For (int i = 0; i < str.length(); i++)
{
Char chr = str.charAt(i);
If (!Character.isLetter(chr))
System.out.print(Character.toUpperCase(chr));
}

A) ABC
B) ABC456
C) 456
D) abc456
C
4
Which of the following statements is not true about the following code?
StringBuilder strb =
New StringBuilder("Total number of parts: ");
Strb.insert(23, 32);

A) The starting position for the insert is 23.
B) strb is a StringBuilder type object.
C) The ending position for the insert is 32.
D) The literal number 32 will be inserted into the string.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
5
Which of the following statements converts a String object variable named str to an int and stores the value in the variable x?

A) int x = Integer.integer(str);
B) int x = str;
C) int x = Integer.parseInteger(str);
D) int x = Integer.parseInt(str);
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
6
What will be displayed after the following code is executed?
String str = "RSTUVWXYZ";
System.out.println(str.charAt(5));

A) W
B) X
C) V
D) U
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
7
What will be displayed after the following statements are executed?
StringBuilder strb =
New StringBuilder("We have lived in Chicago, Trenton, and Atlanta.");
Strb.replace(17, 24, "Tampa");
System.out.println(strb);

A) We have lived in Tampa, Trenton, and Atlanta.
B) We have lived in Chicago, Trenton, and Tampa.
C) We have lived in Chicago, Tampaon, and Atlanta.
D) We have lived in Chicago, Tampa, and Atlanta.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
8
Which of the following import statements is required to use the StringTokenizer class?

A) import java.util.Scanner
B) import java.text.DecimalFormat;
C) import java.util.StringTokenizer;
D) import javax.swing.JOptionPane;
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
9
What will be the value of position after the following code is executed?
Int position;
String str = "The cow jumped over the moon.";
Position = str.lastIndexOf("ov", 14);

A) 14
B) 1
C) 0
D) -1
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
10
A series of words or other items of data separated by spaces or other characters are known as

A) strings.
B) tokens.
C) delimiters.
D) captions.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
11
Which of the following are used as delimiters if the StringTokenizer class's constructor is called and a reference to a String object is passed as the only argument?

A) space
B) tab
C) newline
D) All of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
12
What will be the tokens in the following statement?
StringTokenizer st =
New StringTokenizer("9-14-2014", "-", true);

A) 9, 14, and 2014
B) 9, 14, 2014, and -
C) -
D) None of the above
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
13
Which of the following statements converts a double variable named tax to a string and stores the value in the String object variable named str?

A) String str = Double.toString(tax);
B) String str = double(tax);
C) String str = double.toString(tax);
D) String str = tax.Double.toString(str);
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
14
The Character wrapper class provides numerous methods for

A) converting objects to primitive data types.
B) testing and converting character data.
C) testing and converting numeric literals.
D) performing operations with named constants.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
15
Which of the following statements will display the maximum value that a double can hold?

A) System.out.println(Double.MAX_VALUE);
B) System.out.println(Double.MAXIMUM_VALUE);
C) System.out.println(Double.MAX_VAL);
D) System.out.println((MAX_VALUE));
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
16
What will be displayed after the following code has been executed?
String str1 = "The quick brown fox jumped over the lazy dog."; String str2 = str1.substring(20, 26);
System.out.println(str2);

A) n fox
B) jumped
C) lazy d
D) x jump
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
17
For the following code, how many times would the while loop execute?
StringTokenizer st =
New StringTokenizer("Java programming is fun!");
While (st.hasMoreTokens())
System.out.println(st.nextToken());

A) 7
B) 4
C) 5
D) 1
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
18
In the following statement, what data type must recField be?
Str)getChars(5, 10, recField, 0);

A) int
B) char[]
C) char
D) String
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
19
What will be displayed after the following code has been executed?
Boolean matches;
String str1 = "The cow jumped over the moon.";
String str2 = "moon";
Matches = str1.endsWith(str2);
System.out.println(matches);

A) true
B) moon
C) false
D) The cow
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
20
The ________ method returns a copy of the calling String object, in which all leading and trailing whitespace characters have been deleted.

A) remove
B) trim
C) compress
D) concat
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
21
When working with the String and StringBuilder class's getChars method, the character at the start position is included in the substring, but the character at the end position is not included.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
22
Any ________ argument passed to the Character class's toLowerCase method or toUpperCase method is returned as it is.

A) nonletter
B) char
C) string
D) static
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
23
What will be displayed after the following statements are executed?
String str = "red$green&blue#orange";
String[] tokens = str.split("[$&#]");
For (String s : tokens)
System.out.print(s + " ");

A) red green blue orange
B) Red $ green & blue # orange
C) $ & #
D) red [$&#] green [$&#] blue [$&#] orange
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
24
StringBuilder objects are not immutable.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
25
You can concatenate String objects by

A) using the concat or trim methods.
B) using the concat method or the + operator.
C) using the concatenate or join methods.
D) using the concatenate method or the + operator.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
26
The String class's regionMatches method performs a case-insensitive comparison.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
27
The term ________ commonly is used to refer to a string that is part of another string.

A) nested string
B) literal
C) substring
D) delimiter
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
28
A wrapper class is a class that is "wrapped around" a primitive data type and allows you to create objects instead of variables.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
29
If a string has more than one character used as a delimiter, we must write a loop to determine the tokens, one for each delimiter character.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
30
What will be the value of position after the following code is executed?
Int position;
String str = "The cow jumped over the moon.";
Position = str.indexOf("ov");

A) 14
B) 15
C) 18
D) 17
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
31
You will cause an off-by-one error, when working with a character position within a string, if you think of the first position in a string as 1.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
32
Most of the String comparison methods are case sensitive.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
33
The ________ class is the wrapper class for the char data type.

A) StringBuilder
B) Integer
C) Character
D) String
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
34
Trying to extract more tokens than exist from a StringTokenizer object will cause an error.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
35
Which of the following import statements is required to use the Character wrapper class?

A) import java.String
B) import java.lang.Char
C) import java.Char
D) No import statement is needed
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
36
You cannot assign a value to a wrapper class object.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
37
What will be displayed after the following statements are executed?
StringBuilder strb = new StringBuilder(12);
Strb.append("The cow ");
Strb.append("jumped over the ");
Strb.append("moon.");
System.out.println(strb);

A) The cow jumped over the moon.
B) The cow jumped over the
Moon.
C) The cow jump
D) 12The cow jumped over the moon.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
38
The String class's valueOf method accepts a string representation as an argument and returns its equivalent integer value.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
39
The String class's ________ method accepts a value of any primitive data type as its argument and returns a string representation of the value.

A) trim
B) getChar
C) toString
D) valueOf
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
40
In the ________ file format, when the data in a spreadsheet is exported, each row is written to a line, and the values in the cells are separated by commas.

A) comma separated value
B) extensible markup language
C) excel binary
D) data interchange
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 40 flashcards in this deck.