Multiple choice

StringBuffer s = new StringBuffer(“Welcome To Java”); s.delete(8,12);

What will be the output of the given code segment?

  1. Welcome ava

  2. Welcome va

  3. Welcomeava

  4. Compiler error : delete cannot be used with StringBuffer

  5. Runtime error

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

This is the correct answer. delete(int start , int end) method deletes the characters from the start index until  the end -1 index. So, the welcome to java will delete the characters from 8 to 11 characters. Therefore, the resulting string remains “ Welcome ava”. The index starts from 0.