Bird
0
0

Given this code:

hard📝 Application Q9 of 15
Java - Strings and String Handling
Given this code:
StringBuilder sb = new StringBuilder("abc");
sb.insert(1, "123");
sb.delete(2, 4);
System.out.println(sb);

What is the output?
Aa1bc
Ba13bc
Ca123bc
Da23bc
Step-by-Step Solution
Solution:
  1. Step 1: Insert "123" at index 1 in "abc"

    Result after insert: "a123bc".
  2. Step 2: Delete characters from index 2 to 3 (4 excluded)

    Characters at index 2 and 3 are '2' and '3', so after deletion: "a1bc".
  3. Final Answer:

    a1bc -> Option A
  4. Quick Check:

    Insert then delete correct substring [OK]
Quick Trick: Insert adds text; delete removes specified range [OK]
Common Mistakes:
  • Miscounting indexes for delete
  • Confusing insert position

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes