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 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) delete 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.So this is the correct answer.