Menu
Topics Index
...
`

Delete CharAt


If you need explanation Read this topic

If you need Answer Take test on this topic

Delete CharAt
What will be the output of the following program?
public class UsingChar {
    public static void main(String args[]) {
        StringBuffer buf = new StringBuffer("Shekar started business");
        buf.charAt(5);
        System.out.print(buf);
        buf = buf.deleteCharAt(buf.charAt(5));
    }
}

A. Sheka started business
B. Shekarstarted business
C. Shekar started business
D. Compilation Error
E. Runtime Error
Topic: Java delete() and deleteCharAt() Methods In StringBuffer

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

Ans is E
Runtime error will come i.e. stringOutOfBounds String index out of range: 114 because syntax for deleteCharAt is as follows:

public StringBuilder deleteCharAt(int index)

but in the program buf.charAt(5) returns character "r" whose ascii value is 114 but as "R" is not int so runtime error will come

Posted by Cool Pawan    2014-07-18 17:54:42


E...StringIndexOutOfBoundsException
B'coz deleteCharAt()expects parameter as Integer type. But here it returns 'character'...

Posted by Rajashekar Jadala    2014-07-19 04:16:57


Congratulations Cool Pawan. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-07-21 04:17:39


© meritcampus 2019

All Rights Reserved.

Open In App