java - How can StringBuilder read more than 16 empty elements? -


here code:

   public class stringclass    {    public static void main(string args[])    {     stringbuilder s=new stringbuilder();     s.append("v g f j v n x jc kn vd df jdf jkd kfd kfk dfkd lkd fmk dkkdfd kfdkfn kdfd end");     system.out.println(s);    }    } 

and output

    v g f j v n x jc kn vd df jdf jkd kfd kfk dfkd lkd fmk dkkdfd kfdkfn kdfd end 

according [java docs] (http://docs.oracle.com/javase/tutorial/java/data/buffers.html) string builder can store 16 empty characters,so how able characters output.

if write code output same:

    public class stringclass     {     public static void main(string args[])     {      stringbuilder s=new stringbuilder("v g f j v n x jc kn vd df jdf jkd kfd kfk dfkd lkd fmk dkkdfd kfdkfn kdfd end");        system.out.println(s);      }      } 

you misread that. documentation speaks of initial capacity. "space", should read "empty cell can put character".

the underlying array storing characters has given initial size (capacity) default 16 , grows automatically when needed.


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -