Multiple choice

What will be the output of the given code segment? StringBuffer s = new StringBuffer(�Welcome To Java�);

s.delete(8,12);

  1. Welcome ava

  2. Welcome va

  3. Welcomeava

  4. Compiler error : delete cannot be used with StrinBuffer

  5. Run time error

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

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