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
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/60
Play
Full screen (f)
Deck 9: Text Processing and More About Wrapper Classes
1
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".
D
2
If your program needs to make a lot of changes to one or more string, you might consider using objects of this class:
A) Character
B) String
C) StringBuilder
D) All of the above
A) Character
B) String
C) StringBuilder
D) All of the above
C
3
Which of the following methods 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
A
4
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 60 flashcards in this deck.
Unlock Deck
k this deck
5
In the following statement, what data type must recField be?
Str)getChars(5, 10, recField, 0);
A) String
B) int
C) char
D) char[]
Str)getChars(5, 10, recField, 0);
A) String
B) int
C) char
D) char[]
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
6
What will be the tokens for the following code?
String str = "123-456-7890";
String[] tokens = str.split("-");
A) 123, 456, and 7890
B) -
C) 123, 456, 7890, and -
D) None of the above
String str = "123-456-7890";
String[] tokens = str.split("-");
A) 123, 456, and 7890
B) -
C) 123, 456, 7890, and -
D) None of the above
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
7
When you are writing a program with String objects that may have unwanted spaces at the beginning or end of the strings, use this method to delete them.
A) replace
B) trim
C) valueOf
D) substring
A) replace
B) trim
C) valueOf
D) substring
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
8
Sometimes a string will contain a series of words or other items of data separated by spaces or other characters. In programming terms, items such as these are known as what?
A) Tokens
B) Delimiters
C) Key characters
D) Lists
A) Tokens
B) Delimiters
C) Key characters
D) Lists
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
9
When using the StringBuilder class's insert method, you can insert:
A) any primitive type
B) a String object
C) a char array
D) All of the above
A) any primitive type
B) a String object
C) a char array
D) All of the above
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
10
What is the term used for the character that separates tokens?
A) tokenizer
B) delimiter
C) whitespace
D) separator
A) tokenizer
B) delimiter
C) whitespace
D) separator
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
11
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
Boolean matches;
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 60 flashcards in this deck.
Unlock Deck
k this deck
12
Assuming that str is declared as follows: String str = "RSTUVWXYZ";
What value will be returned from str.charAt(5)?
A) U
B) V
C) W
D) X
What value will be returned from str.charAt(5)?
A) U
B) V
C) W
D) X
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
13
Look at the following statement: StringBuilder str = new StringBuilder(25);
What will the StringBuilder constructor do?
A) give the object, str, 25 bytes of storage and store spaces in them
B) give the object, str, 25 bytes of storage and not store anything in them
C) give the object, str, 25 or more bytes of storage and store spaces in them
D) give the object, str, 0 bytes of storage
What will the StringBuilder constructor do?
A) give the object, str, 25 bytes of storage and store spaces in them
B) give the object, str, 25 bytes of storage and not store anything in them
C) give the object, str, 25 or more bytes of storage and store spaces in them
D) give the object, str, 0 bytes of storage
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
14
What will be the value of loc after the following code is executed?
Int loc;
String str = "The cow jumped over the moon.";
Loc = str.indexOf("ov");
A) 15
B) 16
C) 17
D) 18
Int loc;
String str = "The cow jumped over the moon.";
Loc = str.indexOf("ov");
A) 15
B) 16
C) 17
D) 18
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
15
The Character wrapper class provides numerous methods for:
A) testing String objects
B) testing and converting char variables
C) converting String variables
D) adding two char variables
A) testing String objects
B) testing and converting char variables
C) converting String variables
D) adding two char variables
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
16
What is 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 60 flashcards in this deck.
Unlock Deck
k this deck
17
What will be the value of str after the following statements are executed?
StringBuilder str =
New StringBuilder("We have lived in Chicago, " +
"Trenton, and Atlanta.");
Str)replace(17, 24, "Tampa");
A) We have lived in Tampa, Trenton, and Atlanta.
B) We have lived in Chicago, Tampa, and Atlanta.
C) We have lived in Tampa Trenton, and Tampa.
D) We have lived in Tampalanta.
StringBuilder str =
New StringBuilder("We have lived in Chicago, " +
"Trenton, and Atlanta.");
Str)replace(17, 24, "Tampa");
A) We have lived in Tampa, Trenton, and Atlanta.
B) We have lived in Chicago, Tampa, and Atlanta.
C) We have lived in Tampa Trenton, and Tampa.
D) We have lived in Tampalanta.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
18
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
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
19
The process of breaking a string down into tokens is known as what?
A) tokenizing
B) buffering
C) simplifying
D) parsing
A) tokenizing
B) buffering
C) simplifying
D) parsing
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
20
This character is one that appears at the end, or right side, of a string, after the non-space characters:
A) Leading whitespace
B) Carriage return
C) Trailing whitespace
D) Line feed
A) Leading whitespace
B) Carriage return
C) Trailing whitespace
D) Line feed
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
21
For the following code, how many times would 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 60 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 this many characters.
A) 0 characters
B) 8 characters
C) 16 characters
D) 32 characters
A) 0 characters
B) 8 characters
C) 16 characters
D) 32 characters
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
23
This is the process of converting a wrapper class object to a primitive type.
A) simplifying
B) unboxing
C) parsing
D) devaluating
A) simplifying
B) unboxing
C) parsing
D) devaluating
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
24
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 60 flashcards in this deck.
Unlock Deck
k this deck
25
What would be the results of executing the following code?
StringBuilder str = new StringBuilder(12);
Str)append("The cow");
Str)append(" jumped over the ");
Str)append("moon.");
A) The program would crash.
B) str would reference "The cow jump".
C) str would reference "The cow jumped over the ".
D) str would reference "The cow jumped over the moon."
StringBuilder str = new StringBuilder(12);
Str)append("The cow");
Str)append(" jumped over the ");
Str)append("moon.");
A) The program would crash.
B) str would reference "The cow jump".
C) str would reference "The cow jumped over the ".
D) str would reference "The cow jumped over the moon."
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
26
If str is declared as: String str = "ABCDEFGHI";
What will be returned from Character.toLowerCase(str.charAt(5))?
A) e
B) E
C) f
D) F
What will be returned from Character.toLowerCase(str.charAt(5))?
A) e
B) E
C) f
D) F
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
27
Given the following statement, which of the following 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.
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.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
28
Two ways of concatenating two Strings are:
A) Use the concat() method or use the + between the two Strings
B) Use the concatenate() method or use the + between the two Strings
C) Use the contenate() method or the concat() method
D) Use the concat() method or the trim() method
A) Use the concat() method or use the + between the two Strings
B) Use the concatenate() method or use the + between the two Strings
C) Use the contenate() method or the concat() method
D) Use the concat() method or the trim() method
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
29
For the following code, how many times would 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 60 flashcards in this deck.
Unlock Deck
k this deck
30
What will be the tokens given the following statements?
String str = ("January 1, 2016");
String[] tokens = str.split(" ");
A) The tokens will be: January
1,
2016
B) The tokens will be: ,
Space
C) The tokens will be: January
1
2016
Space
D) The tokens will be: January
Space
1
,
Space
2016
String str = ("January 1, 2016");
String[] tokens = str.split(" ");
A) The tokens will be: January
1,
2016
B) The tokens will be: ,
Space
C) The tokens will be: January
1
2016
Space
D) The tokens will be: January
Space
1
,
Space
2016
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
31
When using the String class's trim method, which of the following 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 60 flashcards in this deck.
Unlock Deck
k this deck
32
To convert the string, str = "285.74" to a double, use the following statement:
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 60 flashcards in this deck.
Unlock Deck
k this deck
33
Use the following import statement when using the Character wrapper class:
A) import java.Char
B) import java.lang.Char
C) import java.String
D) No import statement is needed
A) import java.Char
B) import java.lang.Char
C) import java.String
D) No import statement is needed
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
34
What does the following statement do?
Double number = new Double(8.8);
A) It creates a Double object.
B) It initializes that object to 8.8.
C) It assigns the object's address to the number variable.
D) All of the above
Double number = new Double(8.8);
A) It creates a Double object.
B) It initializes that object to 8.8.
C) It assigns the object's address to the number variable.
D) All of the above
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
35
Which of the following statements will print the maximum value a double variable may have?
A) System.out.println(MAX_VALUE);
B) System.out.println(double.MAX_VALUE);
C) System.out.println(Double.MAX_VALUE);
D) System.out.println(Double.MAXIMUM_VALUE);
A) System.out.println(MAX_VALUE);
B) System.out.println(double.MAX_VALUE);
C) System.out.println(Double.MAX_VALUE);
D) System.out.println(Double.MAXIMUM_VALUE);
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
36
To convert the int variable, number to a string, use the following statement:
A) String str = Integer.toString(number);
B) String str = integer.toString(number);
C) String str = integer(number);
D) String str = number.Integer.toString(str);
A) String str = Integer.toString(number);
B) String str = integer.toString(number);
C) String str = integer(number);
D) String str = number.Integer.toString(str);
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
37
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) 456
B) ABC456
C) ABC
D) abc456
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) 456
B) ABC456
C) ABC
D) abc456
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
38
What will be the value of matches after the following code has been executed?
Boolean matches;
String str1 = "The cow jumped over the moon.";
String str2 = "moon";
Matches = str1.endsWith(str2);
A) true
B) False
C) moon
D) The cow
Boolean matches;
String str1 = "The cow jumped over the moon.";
String str2 = "moon";
Matches = str1.endsWith(str2);
A) true
B) False
C) moon
D) The cow
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
39
What will be the value of loc after the following code is executed?
Int loc;
String str = "The cow jumped over the moon.";
Loc = str.lastIndexOf("ov", 14);
A) 15
B) 16
C) 0
D) -1
Int loc;
String str = "The cow jumped over the moon.";
Loc = str.lastIndexOf("ov", 14);
A) 15
B) 16
C) 0
D) -1
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
40
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 60 flashcards in this deck.
Unlock Deck
k this deck
41
If a non-letter is passed to the toLowerCase or toUpperCase method, it is returned unchanged.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
42
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 60 flashcards in this deck.
Unlock Deck
k this deck
43
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 60 flashcards in this deck.
Unlock Deck
k this deck
44
What does the following statement do?
Float number = new Float(8.8);
A) It creates a Float object.
B) It initializes that object to 8.8.
C) It assigns the object's address to the number variable.
D) All of the above
Float number = new Float(8.8);
A) It creates a Float object.
B) It initializes that object to 8.8.
C) It assigns the object's address to the number variable.
D) All of the above
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
45
Look at the following code. Integer myNumber;
MyNumber = 5;
Which of the following is TRUE about the second statement?
A) It results in an error because you cannot assign a primitive type to a wrapper class object.
B) The statement performs autoboxing.
C) The statement performs unboxing.
D) The statement performs autowrapping.
MyNumber = 5;
Which of the following is TRUE about the second statement?
A) It results in an error because you cannot assign a primitive type to a wrapper class object.
B) The statement performs autoboxing.
C) The statement performs unboxing.
D) The statement performs autowrapping.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
46
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 60 flashcards in this deck.
Unlock Deck
k this deck
47
You must call a method to get the value of a wrapper class object.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
48
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 60 flashcards in this deck.
Unlock Deck
k this deck
49
The following statement correctly creates a StringBuilder object.
StringBuilder str = "Caesar Salad";
StringBuilder str = "Caesar Salad";
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
50
You cannot assign a value to a wrapper class object.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
51
Autoboxing is:
A) Java's process of automatically "boxing up" a value inside an object
B) The automatic allocation 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 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 60 flashcards in this deck.
Unlock Deck
k this deck
52
Look at the following code: Integer myNumber = new Integer(5);
Int var = myNumber;
Which of the following is TRUE about the second statement?
A) It results in an error because you cannot assign a wrapper class object to a primitive variable.
B) The statement performs autoboxing.
C) The statement performs unboxing.
D) The statement performs unwrapping.
Int var = myNumber;
Which of the following is TRUE about the second statement?
A) It results in an error because you cannot assign a wrapper class object to a primitive variable.
B) The statement performs autoboxing.
C) The statement performs unboxing.
D) The statement performs unwrapping.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
53
If more than one character is 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 60 flashcards in this deck.
Unlock Deck
k this deck
54
To convert the string, str = "285" to an int, use the following statement:
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 60 flashcards in this deck.
Unlock Deck
k this deck
55
What will be the tokens in the following statement?
String str = "red$green&blue#orange";
String[] tokens = str.split("[$&#]");
A) "red", "green", "blue", and "orange"
B) "$", "&", and "#"
C) "[", "$", "&", "#", and "]"
D) None of the above
String str = "red$green&blue#orange";
String[] tokens = str.split("[$&#]");
A) "red", "green", "blue", and "orange"
B) "$", "&", and "#"
C) "[", "$", "&", "#", and "]"
D) None of the above
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
56
StringBuilder objects are immutable.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
57
To convert the double variable, d = 543.98, to a string, use the following statement:
A) String str = Double.toString(d);
B) String str = double.toString(d);
C) String str = double(d);
D) String str = d.Double.toString(str);
A) String str = Double.toString(d);
B) String str = double.toString(d);
C) String str = double(d);
D) String str = d.Double.toString(str);
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
58
The String class's valueOf() method accepts a value of any primitive data type as an argument and returns a string representation of the value.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
59
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 60 flashcards in this deck.
Unlock Deck
k this deck
60
You can change the contents of a StringBuilder object, but you cannot change the contents of a String object.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck