Deck 8: Text Processing and 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
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/40
Play
Full screen (f)
Deck 8: Text Processing and Wrapper Classes
1
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(
A
2
StringBuilder objects are not immutable.
True
3
Most of the String comparison methods are case sensitive.
True
4
You may cause an off-by-one error when working with a character position within a string if you think of the first position in the string as 1.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
5
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
6
In the __________ file format, when data in a spreadsheet is exported, each row is written to a line and commas are used to separate the values in the cells.
A) comma separated value
B) extensible markup language
C) excel binary
D) data interchange
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
7
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
8
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 40 flashcards in this deck.
Unlock Deck
k this deck
9
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 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
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
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 40 flashcards in this deck.
Unlock Deck
k this deck
12
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;
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
13
Which of the following statements converts a double variable named tax to a string and stores the value in the String object 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);
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
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 40 flashcards in this deck.
Unlock Deck
k this deck
15
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
16
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
17
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 40 flashcards in this deck.
Unlock Deck
k this deck
18
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 40 flashcards in this deck.
Unlock Deck
k this deck
19
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
20
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 40 flashcards in this deck.
Unlock Deck
k this deck
21
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 40 flashcards in this deck.
Unlock Deck
k this deck
22
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 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
23
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 40 flashcards in this deck.
Unlock Deck
k this deck
24
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.
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
25
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 40 flashcards in this deck.
Unlock Deck
k this deck
26
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 40 flashcards in this deck.
Unlock Deck
k this deck
27
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
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
28
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 40 flashcards in this deck.
Unlock Deck
k this deck
29
What are the tokens in the following statement?
StringTokenizer st = new StringTokenizer("9-14-2018", "-", true);
A) 9, 14, 2018
B) 9, 14, 2018, and -
C) -
D) None of these
StringTokenizer st = new StringTokenizer("9-14-2018", "-", true);
A) 9, 14, 2018
B) 9, 14, 2018, and -
C) -
D) None of these
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
30
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 40 flashcards in this deck.
Unlock Deck
k this deck
31
Which of the following is(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 these
A) space
B) tab
C) newline
D) All of these
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
32
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 40 flashcards in this deck.
Unlock Deck
k this deck
33
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 40 flashcards in this deck.
Unlock Deck
k this deck
34
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.
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
35
Given the following code, how many times will the while loop be executed? StringTokenizer st = new StringTokenizer("Java programming is fun!");
While (st.hasMoreTokens())
System.out.println(st.nextToken());
A) 7
B) 4
C) 5
D) 1
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
36
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
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
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
37
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 40 flashcards in this deck.
Unlock Deck
k this deck
38
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.
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
39
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 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
40
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
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