Deck 7: Characters, Strings, and the Stringbuilder
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
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/73
Play
Full screen (f)
Deck 7: Characters, Strings, and the Stringbuilder
1
The StringBuilder class is more efficient than the StringBuffer class because it can execute multiple threads during program execution.
False
2
A literal string is a(n) ____ object.
A) lost
B) anonymous
C) class
D) named
A) lost
B) anonymous
C) class
D) named
B
3
A String variable name is not a simple data type.
True
4
Strings and other objects that can't be changed are known as ____.
A) string constants
B) accessor methods
C) immutable
D) garbage
A) string constants
B) accessor methods
C) immutable
D) garbage
Unlock Deck
Unlock for access to all 73 flashcards in this deck.
Unlock Deck
k this deck
5
The Character class ____ from java.lang.Object.
A) calls
B) inherits
C) refers
D) spawns
A) calls
B) inherits
C) refers
D) spawns
Unlock Deck
Unlock for access to all 73 flashcards in this deck.
Unlock Deck
k this deck
6
Methods that return information about an object are called accessor methods.
Unlock Deck
Unlock for access to all 73 flashcards in this deck.
Unlock Deck
k this deck
7
Any string value that is input into a program can be used in arithmetic operations.
Unlock Deck
Unlock for access to all 73 flashcards in this deck.
Unlock Deck
k this deck
8
When using the prewritten equals() method, a true or false comparison between two Strings is returned, but you do not know how the code looks behind the scenes.
Unlock Deck
Unlock for access to all 73 flashcards in this deck.
Unlock Deck
k this deck
9
If you try to use an index that is less than 0 or less than the index of the last position in the StringBuilder object, you cause an error known as an exception and your program terminates.
Unlock Deck
Unlock for access to all 73 flashcards in this deck.
Unlock Deck
k this deck
10
In a compareTo() method, programmers often do not need specific return values but want to determine if a value is positive or negative.
Unlock Deck
Unlock for access to all 73 flashcards in this deck.
Unlock Deck
k this deck
11
The methods of the Character class that begin with ____ return a character that has been converted to the stated format.
A) is
B) to
C) for
D) in
A) is
B) to
C) for
D) in
Unlock Deck
Unlock for access to all 73 flashcards in this deck.
Unlock Deck
k this deck
12
A ____ is a class for storing and manipulating changeable data that is composed of multiple characters.
A) Character
B) String
C) StringVariable
D) StringBuilder
A) Character
B) String
C) StringVariable
D) StringBuilder
Unlock Deck
Unlock for access to all 73 flashcards in this deck.
Unlock Deck
k this deck
13
The method header of the equals() method within the String class is ____.
A) public boolean equals(Strings)
B) private boolean equals(String s)
C) public boolean equals(String s)
D) public boolean equals(Character s)
A) public boolean equals(Strings)
B) private boolean equals(String s)
C) public boolean equals(String s)
D) public boolean equals(Character s)
Unlock Deck
Unlock for access to all 73 flashcards in this deck.
Unlock Deck
k this deck
14
When working with Strings, it is necessary to explicitly set a String to null.
Unlock Deck
Unlock for access to all 73 flashcards in this deck.
Unlock Deck
k this deck
15
A(n) ____ comparison is based on the integer Unicode values of the characters.
A) integer
B) symbol
C) lexicographical
D) character
A) integer
B) symbol
C) lexicographical
D) character
Unlock Deck
Unlock for access to all 73 flashcards in this deck.
Unlock Deck
k this deck
16
The String class ____ method evaluates the contents of two String objects to determine if they are equivalent.
A) equals()
B) toString()
C) charAt()
D) replace()
A) equals()
B) toString()
C) charAt()
D) replace()
Unlock Deck
Unlock for access to all 73 flashcards in this deck.
Unlock Deck
k this deck
17
When you declare a variable of a basic, primitive type, such as int x = 10;, the memory address where x is located holds the ____.
A) location in memory of 10
B) memory address of 10
C) reference to 10
D) value of 10
A) location in memory of 10
B) memory address of 10
C) reference to 10
D) value of 10
Unlock Deck
Unlock for access to all 73 flashcards in this deck.
Unlock Deck
k this deck
18
The terms "literal string" and "string literal" are entirely different in Java programming.
Unlock Deck
Unlock for access to all 73 flashcards in this deck.
Unlock Deck
k this deck
19
A(n) ____ is a variable that holds a memory address.
A) reference
B) Character
C) buffer
D) immutable
A) reference
B) Character
C) buffer
D) immutable
Unlock Deck
Unlock for access to all 73 flashcards in this deck.
Unlock Deck
k this deck
20
When you compare Strings with the == operator, you are comparing their values, not their memory addresses.
Unlock Deck
Unlock for access to all 73 flashcards in this deck.
Unlock Deck
k this deck
21
String oneStr = "Welcome Jim" String twoStr = "Welcome Joe"
Given the lines of code above, which of the following regionMatches() expressions will result in a value of true?
A) oneStr.regionMatches(8, twoStr, 8, 3)
B) oneStr.regionMatches(0, twoStr, 0, 7)
C) oneStr.regionMatches(8, twoStr, 0, 3)
D) oneStr.regionMatches(0, twoStr, 8, 3)
Given the lines of code above, which of the following regionMatches() expressions will result in a value of true?
A) oneStr.regionMatches(8, twoStr, 8, 3)
B) oneStr.regionMatches(0, twoStr, 0, 7)
C) oneStr.regionMatches(8, twoStr, 0, 3)
D) oneStr.regionMatches(0, twoStr, 8, 3)
Unlock Deck
Unlock for access to all 73 flashcards in this deck.
Unlock Deck
k this deck
22
The ____ method allows you to replace all occurrences of some character within a String.
A) substring()
B) toString()
C) replaceCharacter()
D) replace()
A) substring()
B) toString()
C) replaceCharacter()
D) replace()
Unlock Deck
Unlock for access to all 73 flashcards in this deck.
Unlock Deck
k this deck
23
System.out.println("Your name is " + yourName); The above statement is an example of ____, which is used to join Strings.
A) concatenation
B) referencing
C) parsing
D) buffering
A) concatenation
B) referencing
C) parsing
D) buffering
Unlock Deck
Unlock for access to all 73 flashcards in this deck.
Unlock Deck
k this deck
24
To convert a String to an integer, you use the valueOf() method of the ____ class.
A) StringBuilder
B) String
C) Integer
D) Convert
A) StringBuilder
B) String
C) Integer
D) Convert
Unlock Deck
Unlock for access to all 73 flashcards in this deck.
Unlock Deck
k this deck
25
The ____ method returns the length of a String.
A) getSize()
B) getLength()
C) size()
D) length()
A) getSize()
B) getLength()
C) size()
D) length()
Unlock Deck
Unlock for access to all 73 flashcards in this deck.
Unlock Deck
k this deck
26
In Java, to ____________________ a String means to break down its separate characters into a numeric format.
Unlock Deck
Unlock for access to all 73 flashcards in this deck.
Unlock Deck
k this deck
27
You can tell that the equals() method takes a ____ argument because parentheses are used in the method call.
A) String
B) Null
C) Double
D) Boolean
A) String
B) Null
C) Double
D) Boolean
Unlock Deck
Unlock for access to all 73 flashcards in this deck.
Unlock Deck
k this deck
28
The ____________________ method requires an integer argument that indicates the position of the character at that position, starting at 0.
Unlock Deck
Unlock for access to all 73 flashcards in this deck.
Unlock Deck
k this deck
29
The ____ is an attribute of the StringBuilder class that identifies the number of characters in the String contained in the StringBuilder.
A) capacity
B) length property
C) reference
D) anonymous object
A) capacity
B) length property
C) reference
D) anonymous object
Unlock Deck
Unlock for access to all 73 flashcards in this deck.
Unlock Deck
k this deck
30
Besides Double and Integer, other wrapper classes such as Float and Long also provide ____ methods that convert Strings to the wrapper types.
A) valueOf()
B) toWrapper()
C) parseString()
D) parseDouble()
A) valueOf()
B) toWrapper()
C) parseString()
D) parseDouble()
Unlock Deck
Unlock for access to all 73 flashcards in this deck.
Unlock Deck
k this deck
31
Which of the following correctly declares and initializes a String object?
A) new String = Hello
B) String greeting == "Hello";
C) String greeting = "Hello";
D) String new = "Hello"
A) new String = Hello
B) String greeting == "Hello";
C) String greeting = "Hello";
D) String new = "Hello"
Unlock Deck
Unlock for access to all 73 flashcards in this deck.
Unlock Deck
k this deck
32
The ____ method converts any object to a String.
A) convertString()
B) toString()
C) replace()
D) substring()
A) convertString()
B) toString()
C) replace()
D) substring()
Unlock Deck
Unlock for access to all 73 flashcards in this deck.
Unlock Deck
k this deck
33
The ____________________ method and the startsWith() method each take a String argument and return true or false if a String object does or does not end or start with the specified argument, respectively.
Unlock Deck
Unlock for access to all 73 flashcards in this deck.
Unlock Deck
k this deck
34
To alter just one character in a StringBuilder, you can use the ____ method, which allows you to change a character at a specified position within a StringBuilder object.
A) charAt()
B) insert()
C) append()
D) setCharAt()
A) charAt()
B) insert()
C) append()
D) setCharAt()
Unlock Deck
Unlock for access to all 73 flashcards in this deck.
Unlock Deck
k this deck
35
The String class ____________________ method is similar to the equals() method. As its name implies, this method ignores case when determining if two Strings are equivalent.
Unlock Deck
Unlock for access to all 73 flashcards in this deck.
Unlock Deck
k this deck
36
The ____ method takes a String argument and returns its double value.
A) parseString()
B) parseInt()
C) parseDouble()
D) returnDouble()
A) parseString()
B) parseInt()
C) parseDouble()
D) returnDouble()
Unlock Deck
Unlock for access to all 73 flashcards in this deck.
Unlock Deck
k this deck
37
The ____ method lets you add characters at a specific location within a StringBuilder object.
A) charAt()
B) insert()
C) append()
D) setCharAt()
A) charAt()
B) insert()
C) append()
D) setCharAt()
Unlock Deck
Unlock for access to all 73 flashcards in this deck.
Unlock Deck
k this deck
38
The creators of Java chose ____ characters as the "extra" length for a StringBuilder object.
A) 12
B) 16
C) 36
D) 48
A) 12
B) 16
C) 36
D) 48
Unlock Deck
Unlock for access to all 73 flashcards in this deck.
Unlock Deck
k this deck
39
The ____________________ class contains standard methods for testing the values of characters.
Unlock Deck
Unlock for access to all 73 flashcards in this deck.
Unlock Deck
k this deck
40
When the String class ____ method is used to compare two Strings, it provides additional information to the user in the form of an integer value.
A) toString()
B) compareTo()
C) equals()
D) equalsIgnoreCase()
A) toString()
B) compareTo()
C) equals()
D) equalsIgnoreCase()
Unlock Deck
Unlock for access to all 73 flashcards in this deck.
Unlock Deck
k this deck
41
How can you change the length of a String in a StringBuilder object?
Unlock Deck
Unlock for access to all 73 flashcards in this deck.
Unlock Deck
k this deck
42
Match each term with the correct statement below.
a.parseDouble()
f.buffer
b.toLowerCase()
g.setLength()
c.substring()
h.indexOf()
d.String variable
i.insert()
e.append()
Determines whether a specific character occurs within a String
a.parseDouble()
f.buffer
b.toLowerCase()
g.setLength()
c.substring()
h.indexOf()
d.String variable
i.insert()
e.append()
Determines whether a specific character occurs within a String
Unlock Deck
Unlock for access to all 73 flashcards in this deck.
Unlock Deck
k this deck
43
Match each term with the correct statement below.
a.parseDouble()
f.buffer
b.toLowerCase()
g.setLength()
c.substring()
h.indexOf()
d.String variable
i.insert()
e.append()
A named object of the String class
a.parseDouble()
f.buffer
b.toLowerCase()
g.setLength()
c.substring()
h.indexOf()
d.String variable
i.insert()
e.append()
A named object of the String class
Unlock Deck
Unlock for access to all 73 flashcards in this deck.
Unlock Deck
k this deck
44
Match each term with the correct statement below.
a.parseDouble()
f.buffer
b.toLowerCase()
g.setLength()
c.substring()
h.indexOf()
d.String variable
i.insert()
e.append()
Returns the lowercase equivalent of the argument
a.parseDouble()
f.buffer
b.toLowerCase()
g.setLength()
c.substring()
h.indexOf()
d.String variable
i.insert()
e.append()
Returns the lowercase equivalent of the argument
Unlock Deck
Unlock for access to all 73 flashcards in this deck.
Unlock Deck
k this deck
45
What is the purpose of the replace() method? Provide an example.
Unlock Deck
Unlock for access to all 73 flashcards in this deck.
Unlock Deck
k this deck
46
Match each term with the correct statement below.
a.parseDouble()
f.buffer
b.toLowerCase()
g.setLength()
c.substring()
h.indexOf()
d.String variable
i.insert()
e.append()
Change the length of a string in a StringBuilder object
a.parseDouble()
f.buffer
b.toLowerCase()
g.setLength()
c.substring()
h.indexOf()
d.String variable
i.insert()
e.append()
Change the length of a string in a StringBuilder object
Unlock Deck
Unlock for access to all 73 flashcards in this deck.
Unlock Deck
k this deck
47
Match each term with the correct statement below.
a.parseDouble()
f.buffer
b.toLowerCase()
g.setLength()
c.substring()
h.indexOf()
d.String variable
i.insert()
e.append()
Add characters at a specific location within a StringBuilder object
a.parseDouble()
f.buffer
b.toLowerCase()
g.setLength()
c.substring()
h.indexOf()
d.String variable
i.insert()
e.append()
Add characters at a specific location within a StringBuilder object
Unlock Deck
Unlock for access to all 73 flashcards in this deck.
Unlock Deck
k this deck
48
How is the String class equalsIgnoreCase() method like the equals() method and how would you use it? Give an example.
Unlock Deck
Unlock for access to all 73 flashcards in this deck.
Unlock Deck
k this deck
49
Describe how a reference is used in Java.
Unlock Deck
Unlock for access to all 73 flashcards in this deck.
Unlock Deck
k this deck
50
Explain what is needed to declare a String variable and provide an example.
Unlock Deck
Unlock for access to all 73 flashcards in this deck.
Unlock Deck
k this deck
51
Match each term with the correct statement below.
a.parseDouble()
f.buffer
b.toLowerCase()
g.setLength()
c.substring()
h.indexOf()
d.String variable
i.insert()
e.append()
Takes two integer arguments: a start position and an end position
a.parseDouble()
f.buffer
b.toLowerCase()
g.setLength()
c.substring()
h.indexOf()
d.String variable
i.insert()
e.append()
Takes two integer arguments: a start position and an end position
Unlock Deck
Unlock for access to all 73 flashcards in this deck.
Unlock Deck
k this deck
52
Describe how a programmer would use the two types of Character class methods (those that begin with "is" and those that begin with "to") for testing the values of characters.
Unlock Deck
Unlock for access to all 73 flashcards in this deck.
Unlock Deck
k this deck
53
Match each term with the correct statement below.
a.parseDouble()
f.buffer
b.toLowerCase()
g.setLength()
c.substring()
h.indexOf()
d.String variable
i.insert()
e.append()
Takes a String argument and returns its double value
a.parseDouble()
f.buffer
b.toLowerCase()
g.setLength()
c.substring()
h.indexOf()
d.String variable
i.insert()
e.append()
Takes a String argument and returns its double value
Unlock Deck
Unlock for access to all 73 flashcards in this deck.
Unlock Deck
k this deck
54
Strings that cannot be changed are said to be immutable. What does this mean and how does it relate to values held in memory addresses?
Unlock Deck
Unlock for access to all 73 flashcards in this deck.
Unlock Deck
k this deck
55
Match each term with the correct statement below.
a.parseDouble()
f.buffer
b.toLowerCase()
g.setLength()
c.substring()
h.indexOf()
d.String variable
i.insert()
e.append()
A memory block
a.parseDouble()
f.buffer
b.toLowerCase()
g.setLength()
c.substring()
h.indexOf()
d.String variable
i.insert()
e.append()
A memory block
Unlock Deck
Unlock for access to all 73 flashcards in this deck.
Unlock Deck
k this deck
56
What is a wrapper and why would you use it?
Unlock Deck
Unlock for access to all 73 flashcards in this deck.
Unlock Deck
k this deck
57
What is the purpose of the substring() method and how do you use it?
Unlock Deck
Unlock for access to all 73 flashcards in this deck.
Unlock Deck
k this deck
58
Match each term with the correct statement below.
a.parseDouble()
f.buffer
b.toLowerCase()
g.setLength()
c.substring()
h.indexOf()
d.String variable
i.insert()
e.append()
Add characters to the end of a StringBuilder object
a.parseDouble()
f.buffer
b.toLowerCase()
g.setLength()
c.substring()
h.indexOf()
d.String variable
i.insert()
e.append()
Add characters to the end of a StringBuilder object
Unlock Deck
Unlock for access to all 73 flashcards in this deck.
Unlock Deck
k this deck
59
How can you use String methods to change the case of a string? Provide an example.
Unlock Deck
Unlock for access to all 73 flashcards in this deck.
Unlock Deck
k this deck
60
Why would you use the append() method? Provide an example.
Unlock Deck
Unlock for access to all 73 flashcards in this deck.
Unlock Deck
k this deck
61
String greeting = "Welcome back";
Using the above statement, write the length() method that will return the length of the greeting String. Store the length in an integer named greetingLength.
Using the above statement, write the length() method that will return the length of the greeting String. Store the length in an integer named greetingLength.
Unlock Deck
Unlock for access to all 73 flashcards in this deck.
Unlock Deck
k this deck
62
StringBuilder greeting = new StringBuilder("Welcome");
Create the append() method to add the characters "home" to the end of the StringBuilder object created above.
Create the append() method to add the characters "home" to the end of the StringBuilder object created above.
Unlock Deck
Unlock for access to all 73 flashcards in this deck.
Unlock Deck
k this deck
63
import javax.swing.JOptionPane;
public class Practice
{
public static void main(String[] args)
{
String fullName;
char firstLetter;
____
____
}
}
Accepting a String from a user is common practice. Using the above code, write the statements to accept a String response from a user. Prompt the user with "Enter your name". Then use the charAt() method to extract the first character of the String.
public class Practice
{
public static void main(String[] args)
{
String fullName;
char firstLetter;
____
____
}
}
Accepting a String from a user is common practice. Using the above code, write the statements to accept a String response from a user. Prompt the user with "Enter your name". Then use the charAt() method to extract the first character of the String.
Unlock Deck
Unlock for access to all 73 flashcards in this deck.
Unlock Deck
k this deck
64
String firstCompare = "Oak Maple Pine"
String secondCompare = "spruce maple elm"
firstCompare.regionMatches(false, 4, secondCompare, 7, 5)
Using the above code, what will be the Boolean value after execution of the regionMatches statement? Explain how the Strings are compared using the regionMatches() method.
String secondCompare = "spruce maple elm"
firstCompare.regionMatches(false, 4, secondCompare, 7, 5)
Using the above code, what will be the Boolean value after execution of the regionMatches statement? Explain how the Strings are compared using the regionMatches() method.
Unlock Deck
Unlock for access to all 73 flashcards in this deck.
Unlock Deck
k this deck
65
String aName = "Michael"
Using the above statement, write the length() method that will return the length of the aName String. What value will the length() method return when executed?
Using the above statement, write the length() method that will return the length of the aName String. What value will the length() method return when executed?
Unlock Deck
Unlock for access to all 73 flashcards in this deck.
Unlock Deck
k this deck
66
String greeting = "Welcome Home";
Using the above String, create the String method to convert the greeting String to all uppercase. Likewise, create the String method to convert the greeting String to all lowercase.
Using the above String, create the String method to convert the greeting String to all uppercase. Likewise, create the String method to convert the greeting String to all lowercase.
Unlock Deck
Unlock for access to all 73 flashcards in this deck.
Unlock Deck
k this deck
67
StringBuilder greeting = new StringBuilder("Welcome home ");
phrase.insert(13, "Joe");
Using the above code and insert() method, describe how the phrase will appear after the code executes. How does the insert() method work?
phrase.insert(13, "Joe");
Using the above code and insert() method, describe how the phrase will appear after the code executes. How does the insert() method work?
Unlock Deck
Unlock for access to all 73 flashcards in this deck.
Unlock Deck
k this deck
68
yourCounty = "perry";
yourCounty.equals("Perry");
yourCounty.equalsIgnoreCase("Perry");
Using the above statements, what value will be returned by the equals() method? What will be the value of the equalsIgnoreCase() method? Explain how the equalsIgnoreCase() method can be useful when users type responses to prompts in programs.
yourCounty.equals("Perry");
yourCounty.equalsIgnoreCase("Perry");
Using the above statements, what value will be returned by the equals() method? What will be the value of the equalsIgnoreCase() method? Explain how the equalsIgnoreCase() method can be useful when users type responses to prompts in programs.
Unlock Deck
Unlock for access to all 73 flashcards in this deck.
Unlock Deck
k this deck
69
yourCounty = "Clark"
yourCounty.startsWith("Cla")
What value will be returned by the startsWith() method? Explain how the startsWith() method deals with case sensitivity.
yourCounty.startsWith("Cla")
What value will be returned by the startsWith() method? Explain how the startsWith() method deals with case sensitivity.
Unlock Deck
Unlock for access to all 73 flashcards in this deck.
Unlock Deck
k this deck
70
String example1 = "";
String example2 = null;
String example3;
There is an important difference between empty Strings and null Strings. Explain the differences and why it is important when making String comparisons.
String example2 = null;
String example3;
There is an important difference between empty Strings and null Strings. Explain the differences and why it is important when making String comparisons.
Unlock Deck
Unlock for access to all 73 flashcards in this deck.
Unlock Deck
k this deck
71
myCounty = " Clark Jackson Scioto"
myCounty.charAt(6)
Using the above code, what will be the value of the charAt() method once the code executes? Explain how the charAt() method operates.
myCounty.charAt(6)
Using the above code, what will be the value of the charAt() method once the code executes? Explain how the charAt() method operates.
Unlock Deck
Unlock for access to all 73 flashcards in this deck.
Unlock Deck
k this deck
72
StringBuilder greeting = new StringBuilder("Day 1");
Using the above StringBuilder, create a setCharAt() method that will change the "1" to a "2" in the String "Day 1". Explain how the setCharAt() method operates.
Using the above StringBuilder, create a setCharAt() method that will change the "1" to a "2" in the String "Day 1". Explain how the setCharAt() method operates.
Unlock Deck
Unlock for access to all 73 flashcards in this deck.
Unlock Deck
k this deck
73
StringBuilder greeting = new StringBuilder("Hello, John");
char initial = greeting.charAt(7);
Using the above code and the charAt() method, what value will be assigned to the variable initial?
char initial = greeting.charAt(7);
Using the above code and the charAt() method, what value will be assigned to the variable initial?
Unlock Deck
Unlock for access to all 73 flashcards in this deck.
Unlock Deck
k this deck