问题 1
The following program displays __________.
public class Test {
public static void main(String[] args) {
String s = "Java";
StringBuilder buffer = new StringBuilder(s);
change(buffer);
System.out.println(buffer);
}
private static void change(StringBuilder buffer) {
buffer.append(" and HTML");
}
}
A.and HTML
B.Java
C.nothing is displayed
D.Java and HTML
问题 2
Assume StringBuilder strBuf is "ABCCEFC", after invoking _________, strBuf contains "ABTTEFT".
A.strBuf.replace('C', "TT")
B.strBuf.replace('C', 'T')
C.strBuf.replace(2, 7, "TTEFT")
D.strBuf.replace("CC", "TT")
E.strBuf.replace("C", "T")
问题 3
If your string does not require any changes, you should use String rather than StringBuffer to improve performance.
A.false
B.true
问题 4
What is the output of the following code?
public class Test {
public static void main(String[] args) {
String s1 = "Welcome to Java!";
String s2 = "Welcome to Java!";
if (s1 == s2)
System.out.println("s1 and s2 reference to the same String object");
else
System.out.println("s1 and s2 reference to different String objects");
}
}
A.s1 and s2 reference to different String objects