Can you solve this Java puzzle?

preview_player
Показать описание

Рекомендации по теме
Комментарии
Автор

The question should be how many memory allocations are made. String builder must allocate some space and if it runs out allocate more. So even if you have one string object you may have more than one allocation

lefteriseleftheriades
Автор

In case of String 27 objects will created and for StringBuilder only 1 object is created, reason behind is String is immutable and StringBuilder is mutable

manigupta
Автор

Way 1 26 string object created
Way 2 one

maheshkumarm