Question 1
Which two statements about text handling in Java are correct? (Choose two.)
A. String is immutable, so replace, toUpperCase, and strip each return a new String and leave the original unchangedCorrect answer
Correct: String is immutable, so replace, toUpperCase, strip and every other apparent 'mutator' return a brand-new String and leave the original untouched.
B. StringBuilder.reverse() returns a new StringBuilder and leaves the original builder unchanged
StringBuilder.reverse() reverses the characters in place and returns the same builder (this), not a new object; in-place mutation is exactly what distinguishes StringBuilder from String.
C. As of Java 25, CharSequence declares getChars(int, int, char[], int) as a default method, so every CharSequence implementation exposes itCorrect answer
Correct: as of Java 25, CharSequence declares getChars(int, int, char[], int) as a default method, so every CharSequence implementation (String, StringBuilder, CharBuffer) exposes it, even through a CharSequence reference.
D. The == operator on two String variables compares their character contents, so "ab" == "ab" being true proves == checks characters
== on two String references compares identity, not content; "ab" == "ab" is true only because both literals are interned to one pooled object, not because == inspects characters. Use equals to compare content.
Explanation
String is immutable, so its transforming methods return new instances and never change the original, whereas StringBuilder mutates in place and returns the same builder. As of Java 25 CharSequence provides getChars as a default method available to every implementation through the interface. Content comparison of strings requires equals; == tests only reference identity, which can coincidentally hold for interned literals.