Deck 9: Text Processing and More About Wrapper Classes
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/62
Play
Full screen (f)
Deck 9: Text Processing and More About Wrapper Classes
1
You cannot assign a value to a wrapper class object.
False
2
The term ________ commonly is used to refer to a string that is part of another string.
A) strand
B) substring
C) character fragment
D) nested string
A) strand
B) substring
C) character fragment
D) nested string
B
3
You can change the contents of a StringBuilder object, but you cannot change the contents of a String object.
True
4
What is the term used for a class that is "wrapped around" a primitive data type and allows you to create objects instead of variables?
A) intrinsic class
B) enclosed object
C) wrapper class
D) transitional object
A) intrinsic class
B) enclosed object
C) wrapper class
D) transitional object
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
5
If a non-letter is passed to the toLowerCase or toUpperCase method, it is returned unchanged.
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
6
The following statement correctly creates a StringBuilder object.
StringBuilder str = "Tuna sandwich";
StringBuilder str = "Tuna sandwich";
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
7
The wrapper classes in Java are immutable, which means that once you create an object, you cannot change the object's value.
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
8
The ________ character appears at the end (the right side) of a string, after the non-space characters.
A) leading whitespace
B) character return
C) trailing whitespace
D) line feed
A) leading whitespace
B) character return
C) trailing whitespace
D) line feed
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
9
StringBuilder objects are not immutable.
Unlock Deck
Unlock for access to all 62 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, is known as a __________.
A) string
B) token
C) delimiter
D) caption
A) string
B) token
C) delimiter
D) caption
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
11
If you are using characters other than whitespaces as delimiters, you will probably want to trim the string before tokenizing; otherwise, the leading and/or following whitespaces will become part of the first and/or last token.
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
12
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 62 flashcards in this deck.
Unlock Deck
k this deck
13
The term __________ is commonly used to refer to a string that is part of another string.
A) nested string
B) literal
C) substring
D) delimiter
A) nested string
B) literal
C) substring
D) delimiter
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
14
If a string has more than one character used as a delimiter, you must write a loop to determine the tokens, one for each delimiter character.
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
15
When working with the String and StringBuilder classes' 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 62 flashcards in this deck.
Unlock Deck
k this deck
16
Most of the String comparison methods are case sensitive.
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
17
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 62 flashcards in this deck.
Unlock Deck
k this deck
18
If a non-letter argument is passed to the toLowerCase or toUpperCase method, the boolean value false is returned.
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
19
Trying to extract more tokens than exist from a StringTokenizer object will cause an error.
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
20
The String class's regionMatches method performs a case-insensitive comparison.
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
21
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);
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 62 flashcards in this deck.
Unlock Deck
k this deck
22
The no-arg constructor for a StringBuilder object gives the object enough storage space to hold __________ characters.
A) 0
B) 8
C) 16
D) 32
A) 0
B) 8
C) 16
D) 32
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
23
The process of breaking a string down into tokens is known as __________.
A) tokenizing
B) buffering
C) simplifying
D) parsing
A) tokenizing
B) buffering
C) simplifying
D) parsing
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
24
You can concatenate String objects by using the __________.
A) concat or trim methods
B) concat method or the + operator
C) concatenate or join methods
D) concatenate method or the + operator
A) concat or trim methods
B) concat method or the + operator
C) concatenate or join methods
D) concatenate method or the + operator
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
25
The StringBuilder class's insert method allows you to insert a(n) __________ into the calling object's string.
A) char array
B) primitive type
C) String object
D) All of these
A) char array
B) primitive type
C) String object
D) All of these
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
26
Each of the numeric wrapper classes has a static ________ method that converts a number to a string.
A) GetString
B) Parse
C) ToString
D) Convert
A) GetString
B) Parse
C) ToString
D) Convert
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
27
The __________ class is the wrapper class for the char data type.
A) StringBuilder
B) Integer
C) Character
D) String
A) StringBuilder
B) Integer
C) Character
D) String
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
28
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
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 62 flashcards in this deck.
Unlock Deck
k this deck
29
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 required
A) import java.String;
B) import java.lang.Char;
C) import java.Char;
D) No import statement is required
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
30
The __________ method of the String class can be used to tokenize a string.
A) split
B) tokenize
C) trim
D) length
A) split
B) tokenize
C) trim
D) length
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
31
The __________ method returns a copy of the calling String object with all leading and trailing whitespace characters deleted.
A) remove
B) trim
C) compress
D) concat
A) remove
B) trim
C) compress
D) concat
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
32
When using the String class's trim method, a __________ cannot be trimmed.
A) space
B) tab
C) semicolon
D) newline
A) space
B) tab
C) semicolon
D) newline
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
33
What will be printed after the following code is executed?
String str = "abc456";
Int m = 0;
While ( m < 6 )
{
If (Character.isLetter(str.charAt(m)))
System.out.print(
Character.toUpperCase(str.charAt(m)));
M++;
}
A) abc456
B) ABC456
C) ABC
D) 456
String str = "abc456";
Int m = 0;
While ( m < 6 )
{
If (Character.isLetter(str.charAt(m)))
System.out.print(
Character.toUpperCase(str.charAt(m)));
M++;
}
A) abc456
B) ABC456
C) ABC
D) 456
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
34
The process of converting a wrapper class object to a primitive type is known as __________.
A) simplifying
B) unboxing
C) parsing
D) devaluating
A) simplifying
B) unboxing
C) parsing
D) devaluating
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
35
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) String str = Integer.toString(number);
B) String str = number.Integer.toString(str);
C) String str = integer(number);
D) String str = integer.toString(number);
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
36
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
A) trim
B) getChar
C) toString
D) valueOf
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
37
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
A) nonletter
B) char
C) string
D) static
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
38
The term used for the character that separates tokens is __________.
A) tokenizer
B) delimiter
C) whitespace
D) separator
A) tokenizer
B) delimiter
C) whitespace
D) separator
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
39
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));
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(
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
40
Autoboxing is __________.
A) Java's process of automatically "boxing up" a value inside an object
B) the automatic allocation of array elements
C) the process of assigning a default value to primitive data types
D) the process of identifying tokens in a string
A) Java's process of automatically "boxing up" a value inside an object
B) the automatic allocation of array elements
C) the process of assigning a default value to primitive data types
D) the process of identifying tokens in a string
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
41
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
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 62 flashcards in this deck.
Unlock Deck
k this deck
42
If str is declared as: String str = "ABCDEFGHI";
What will be returned from the following statement?
Character.toLowerCase(str.charAt(5))
A) e
B) E
C) f
D) F
What will be returned from the following statement?
Character.toLowerCase(str.charAt(5))
A) e
B) E
C) f
D) F
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
43
What is the value of str after the following code has been executed?
String str;
String sourceStr = "Hey diddle, diddle, the cat
And the fiddle";
Str = sourceStr.substring(12,17);
A) diddle
B) diddl
C) didd
D) iddle
String str;
String sourceStr = "Hey diddle, diddle, the cat
And the fiddle";
Str = sourceStr.substring(12,17);
A) diddle
B) diddl
C) didd
D) iddle
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
44
In the following statement, what data type must recField be? str.getChars(5, 10, recField, 0);
A) int
B) char[ ]
C) char
D) String
A) int
B) char[ ]
C) char
D) String
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
45
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
System.out.println(str.charAt(5));
A) W
B) X
C) V
D) U
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
46
In the following code, how many times will the for loop execute?
String str = "1,2,3,4,5,6,7,8,9");
String[ ] tokens = str.split(",");
For (String s : tokens)
System.out.println(s);
A) 1
B) 5
C) 7
D) 9
String str = "1,2,3,4,5,6,7,8,9");
String[ ] tokens = str.split(",");
For (String s : tokens)
System.out.println(s);
A) 1
B) 5
C) 7
D) 9
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
47
What would be the results of executing the following code?
StringBuilder str = new StringBuilder("Little Jack
Horner ");
Str)append("sat on the ");
Str)append("corner");
A) The program would crash.
B) str would reference "Little Jack Horner ".
C) str would reference "Little Jac Horner sat on the ".
D) str would reference "Little Jack Horner sat on the corner".
StringBuilder str = new StringBuilder("Little Jack
Horner ");
Str)append("sat on the ");
Str)append("corner");
A) The program would crash.
B) str would reference "Little Jack Horner ".
C) str would reference "Little Jac Horner sat on the ".
D) str would reference "Little Jack Horner sat on the corner".
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
48
In the following code, how many times will the for loop execute?
String str = ("Ben and Jerry's ice cream is great.");
String[ ] tokens = str.split(" ");
For (String s : tokens)
System.out.println(s);
A) 1
B) 3
C) 5
D) 7
String str = ("Ben and Jerry's ice cream is great.");
String[ ] tokens = str.split(" ");
For (String s : tokens)
System.out.println(s);
A) 1
B) 3
C) 5
D) 7
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
49
What will be displayed after the following code is executed? boolean matches;
String str1 = "The cow jumped over the moon.";
String str2 = "moon";
Matches = str1.endsWith(str1);
System.out.println(matches);
A) true
B) moon
C) false
D) The cow
String str1 = "The cow jumped over the moon.";
String str2 = "moon";
Matches = str1.endsWith(str1);
System.out.println(matches);
A) true
B) moon
C) false
D) The cow
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
50
What will be displayed after the following code is 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.
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 62 flashcards in this deck.
Unlock Deck
k this deck
51
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
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
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
52
What are the tokens in the following code? String str = "123-456-7890";
String[ ] tokens = str.split("-");
A) 123, 456,7890
B) 123, 456, 7890,-
C) -
D) None of these
String[ ] tokens = str.split("-");
A) 123, 456,7890
B) 123, 456, 7890,-
C) -
D) None of these
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
53
What are the tokens in the following statement? StringTokenizer st = new StringTokenizer("9-14-2018", "-", true);
A) 9, 14, 2018
B) 9, 14, 2018, -
C) -
D) None of these
A) 9, 14, 2018
B) 9, 14, 2018, -
C) -
D) None of these
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
54
Which of the following statements will convert the string, str = "285" to an int?
A) int x = str;
B) int x = Integer.parseInteger(str);
C) int x = Integer.integer(str);
D) int x = Integer.parseInt(str);
A) int x = str;
B) int x = Integer.parseInteger(str);
C) int x = Integer.integer(str);
D) int x = Integer.parseInt(str);
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
55
What will be displayed after the following code is 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
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 62 flashcards in this deck.
Unlock Deck
k this deck
56
Given the following, which of the statements below is not true? str.insert(8, 32);
A) str is a StringBuilder type object.
B) The insert will start at position 32.
C) The starting position for the insert is 8.
D) The literal number 32 will be inserted.
A) str is a StringBuilder type object.
B) The insert will start at position 32.
C) The starting position for the insert is 8.
D) The literal number 32 will be inserted.
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
57
What will be the value of matches after the following code is executed? boolean matches;
String[ ] productCodes = {"456HI345", "3456hj"};
Matches = productCodes[0].regionMatches(true, 1,
ProductCodes[1], 2, 3);
A) 56H
B) 56h
C) true
D) false
String[ ] productCodes = {"456HI345", "3456hj"};
Matches = productCodes[0].regionMatches(true, 1,
ProductCodes[1], 2, 3);
A) 56H
B) 56h
C) true
D) false
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
58
Which of the following statements will convert the string, str = "285.74" to a double?
A) double x = str;
B) double x = Double.parseDouble(str);
C) double x = Double.Double(str);
D) double x = str.Double.parseDouble;
A) double x = str;
B) double x = Double.parseDouble(str);
C) double x = Double.Double(str);
D) double x = str.Double.parseDouble;
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
59
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
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 62 flashcards in this deck.
Unlock Deck
k this deck
60
Which of the following statements will print the maximum value an int variable may have?
A) System.out.println(MAX_VALUE);
B) System.out.println(integer.MAX_VALUE);
C) System.out.println(Integer.MAX_VALUE);
D) System.out.println(INTEGER.MAX_VALUE);
A) System.out.println(MAX_VALUE);
B) System.out.println(integer.MAX_VALUE);
C) System.out.println(Integer.MAX_VALUE);
D) System.out.println(INTEGER.MAX_VALUE);
Unlock Deck
Unlock for access to all 62 flashcards in this deck.
Unlock Deck
k this deck
61
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.
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 62 flashcards in this deck.
Unlock Deck
k this deck
62
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
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 62 flashcards in this deck.
Unlock Deck
k this deck