String Manipulation FRQ Practice

Responses receive AI feedback against a rubric after submission. Scores are practice estimates.

Question 1 of 5

Consider:

String s = "willow";
String t = s;
s = s + "y";

(a) Give the values of s and t after these statements. (b) Explain why t did not become willowy. (c) Explain what immutability means for the original willow object.

Question 2 of 5

DockTag.toString is supplied.

class DockTag {
    private String id;
    public DockTag(String code) {
        id = code;
    }
    public String toString() {
        return "[" + id + "]";
    }
}

DockTag t = new DockTag("N2");
System.out.print("go" + 2 + t);

(a) Give the displayed text. (b) Explain the concatenation of 2. (c) Explain how t is converted for concatenation.

Question 3 of 5

Let w be "quartz".

(a) Give w.length(). (b) Give w.substring(2, 5). (c) Give w.substring(6) and explain why it is legal.

Question 4 of 5

Let w be "cacao".

(a) Give w.indexOf("ca"). (b) Give w.indexOf("ao"). (c) Give w.indexOf("xy") and explain the result.

Question 5 of 5

Compare strings using only the AP subset.

(a) Give "oak".equals("oak") and "oak".equals("Oak"). (b) State the sign of "oak".compareTo("oaken") without claiming a specific nonzero magnitude. (c) Explain why compareTo’s magnitude should not be treated as a documented distance.