| Author |
doubt with string predefined method
|
Vishal Hegde
Ranch Hand
Joined: Aug 01, 2009
Posts: 973
|
|
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???
|
http://www.lifesbizzare.blogspot.com || OCJP:81%
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
|
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.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
 |
|
|
subject: doubt with string predefined method
|
|
|