public static void main(String args[]){
StringBuilder sb=new StringBuilder();
System.out.println(sb.capacity());
sb.append("abcabcabcabcabcabcab");
System.out.println(sb.length());
System.out.println(sb.capacity());
System.out.println("-----");
sb.append("abcabcabcabcabcabcab");
System.out.println(sb.length());
System.out.println(sb.capacity());
System.out.println("-----");
sb.trimToSize();
System.out.println(sb.capacity());
System.out.println(sb.length());
}
o/p is
16
20
34
-----
40
70
-----
40
40
My question is that in second line, the capacity should be 36(20+16). why is it showing as 34.
Aucun commentaire:
Enregistrer un commentaire