public class SB
{
public static void main(String args[])
{
StringBuffer s1=new StringBuffer();
s1.insert(1,"Hello from Java");
System.out.println(s1);
}
}
why is it giving an exception Stringindexoutofbounds, i havent even specified the range or capacity???
You try to insert a String just before the second character (or just after the first character). But there are no characters, so it tries to insert the String at a location that does not exist. Remember, insertions etc work on the actual contents, not the capacity.