StringBuilder Capacity

chrisdtrinityphysicians used Ask the Experts™
The languages C#.Net and java both have StringBuilder class. In both languages, we can get StringBuilder's capacity. But in C#, we are getting the capacity value as 16, 32, 64, 128, ..., ect. But in Java, we are getting the capacity value as 16, 34, 70, 142, ..., etc.

So in java, 2 bits are extra occupying when comparing with .net, that is why? Can any one please explain me?
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
AndyAinscowFreelance programmer / Consultant
You are comparing chalk and cheese - there is no reason to expect they will bahave the same way when allocating memory.
Glanced up at my screen and thought I had coded the Matrix...  Turns out, I just fell asleep on the keyboard.
Most Valuable Expert 2011
Top Expert 2015
I agree with AndyAinscow:  a language can be designed to have whatever constructs (classes being one such construct if the language supports them) the inventors decide. These constructs can be named whatever the inventors decide. Just because two language each have a construct with the same name, it doesn't mean that they constructs are implemented in the same way. I could create a class named in StringBuilder in PHP, Python, Visual Basic .NET, etc., and each could be implemented in a slightly (or completely) different way. Such is the case with your observation.

In your case, the internal algorithms used to increase the capacity of the SB are different between the two languages observed. Of course each language is open for extension, so you are free to write your own class in each language which behaves exactly the same  = )
Thanks for the nice and immediate response.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial