• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

StringBuffer capacity

 
Ranch Hand
Posts: 522
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

1) on line 2, a string buffer (s) of capacity 16 + 5 = 21 is created.
2) on line 3, we appended ss to s making 16 + 5 = 21, which fits perfectly in s, making the output on line 4 equals to 21.
my question is: if we add another character to ss

the output (capcity) of s becomes 44 !!! isn't suppose that the capacity increases by one, hence becoming 22??
 
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
when using append() for a StringBuffer, the ensureCapacity() method is implicitly called. See JLS1 - StringBuffer
Miki
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic