Question: Need help with Java Chapter 9 exercise. 1. What is the value of the variable named cap after the code that follows is executed? StringBuilder
Need help with Java Chapter 9 exercise.
1. What is the value of the variable named cap after the code that follows is executed?
StringBuilder name = new StringBuilder("Thomas");
int cap = name.capacity();
| a. | 6 | d. | 22 |
| b. | 10 | e. | 28 |
| c. | 16 |
| |
What is the value of s1 after the code that follows is executed?
StringBuilder title = new StringBuilder();
title.append("The Basics of OOP");
title.delete(0, 13);
String s1 = title.toString();
| a. | "The Basics of OOP" | d. | "OOP" |
| b. | "The Basics of" | e. | "The Basics of " |
| c. | " OOP" |
| |
2. What is the value of s1 after the code that follows is executed?
StringBuilder s1 = new StringBuilder();
s1.append("115-88-9525");
s1.deleteCharAt(4);
| a. | 115-8-9525 | c. | 115-88-9525 |
| b. | 11588-9525 | d. | 115889525 |
3. The equality operator (==) checks whether
| a. | two String variables contain the same characters |
| b. | two Strings variables refer to the same String object |
| c. | both a and b |
| d. | none of the above |
4. To make sure your code is thread-safe, you would use the
| a. | StringBuilder class | c. | both a and b |
| b. | StringBuffer class | d. | none of the above |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
