Originally posted by rajashree ghatak:
I am unable to understand the output of the following code:
1: StringBuffer sb2=new StringBuffer(5);
4: //sb2.setCharAt(0,'i'); //compile error.
Output is :
My Questions are : a.)When we set the size of the StringBuffer by
passing the value 5 in the constructor on line 1,how can we give a String whose
length is 6(greater than the size of the buffer)?
b.) what is logic behind the output of statement on line 8,how is the
capacity 12 when it is already set to 5 when StringBuffer object is
c.)in line 5,when any value > 0 is passed as the first argument in
insert() method, StringIndexOutOfBoundsException occurs though on
passing 0,the above output is printed.why is it so?
d.)why does line 4 give compile error when line 5 doesn't?
thanx in advance.
Destiny's powerful hand has made the bed of my future. And this tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your databasehttps://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database