This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Can somebody explain these lines of code?  RSS feed

 
Klaas Vredevort
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I don't understand the StringBuffer function in this file?
 
Joni Salonen
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It creates an empty StringBuffer in which you can put at least 128 characters, without needing to allocate more memory. If you add more than 128 characters it will have to allocate a new, larger internal character buffer.

You are given the option to specify the initial size because in a very tight loop reallocation may degrade performance. Which means that in 99% of the cases you don't need to do it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!