Skip to content

Instantly share code, notes, and snippets.

Created August 23, 2016 14:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/8458cd71e8de262c8fdfb525b6f06911 to your computer and use it in GitHub Desktop.
Save anonymous/8458cd71e8de262c8fdfb525b6f06911 to your computer and use it in GitHub Desktop.
how come the capacity remains same after the third append?
class Sb1{
public static void main(String[] args){
StringBuffer sb=new StringBuffer();
System.out.println(sb.capacity());
System.out.println(sb.length());
StringBuffer sb1=sb.append("abcdefghijklmnopqrstuvwxyzabcdefghijk");
System.out.println("after first append");
System.out.println(sb.capacity());
sb.append("q");
System.out.println("after second append");
System.out.println(sb.capacity());
sb.append("p");
System.out.println("after third append");
System.out.println(sb.capacity());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment