Core Java/J2EE interview questions: - By using String or String Buffer performance increases?

preview_player
Показать описание
Рекомендации по теме
Комментарии
Автор

Why you want to create StringBuffer Instance inside a for loop. StringBuffer is based on decorator pattern to decorate String object and will always cost more if instianted multiple times compare to instianting String object. However we need to measure the memory usage of using String vs String buffer.

vikashk
Автор

In your Dynamic program you are creating the String variable outside the for loop and StringBuffer is created inside the for loop. This is critical and your results are biased.

sumitvyas
join shbcf.ru