QuestionQ161

Working with Selected Classes from the Java API

Which statement empties the contents of a StringBuilder variable called sb?

  • A sb. deleteAll ();
  • B sb. delete (0, sb. size () );
  • C sb. delete (0, sb. length () );
  • D sb. removeAll ();
Explanation

StringBuilder.delete(int, int) removes the character range beginning at the inclusive start index and ending before the exclusive end index. Using 0 and sb.length() therefore deletes all characters in the builder.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!