Given:
public class Main { public static void main(String[] args) { String s = "1234"; StringBuilder sb = new StringBuilder(s.substring(2).concat("56").replace("7", "6")); System.out.println(sb.append("89").insert(3, "x")); } }
What is the result?
B is correct.
The keys to remember are that indexes are 0-based, and that chained methods work from left to right.
Also, the replace()
method's first argument is the character to be replaced, so in this case the replace()
invocation has no effect on the StringBuilder.