DEV Community

Discussion on: Performance Benchmarking: String and String Builder

Collapse
 
dagnelies profile image
Arnaud Dagnelies

I guess what this boils down to is memory allocation. Using strings concatenation, new memory is allocated each time, while using StringBuilder the buffer approximatively doubles in size when needed.

Collapse
 
kaleemniz profile image
Kaleem

Rightly, modifying the String class creates a new String instance in the heap memory, which makes the execution of String append slow.