Bird
0
0

Which of the following is the correct way to append "World" to a StringBuilder named sb?

easy📝 Syntax Q3 of 15
Java - Strings and String Handling
Which of the following is the correct way to append "World" to a StringBuilder named sb?
Asb.insert("World");
Bsb.add("World");
Csb.concat("World");
Dsb.append("World");
Step-by-Step Solution
Solution:
  1. Step 1: Recall StringBuilder methods

    StringBuilder uses append() to add text at the end.
  2. Step 2: Check method names

    add() and concat() are not methods of StringBuilder. insert() inserts at a position, not just append.
  3. Final Answer:

    sb.append("World"); -> Option D
  4. Quick Check:

    Append text with append() method [OK]
Quick Trick: Use append() to add text to StringBuilder [OK]
Common Mistakes:
  • Using concat() which is for String
  • Using add() which does not exist
  • Confusing insert() with append()

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes