Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

String concatenation performance

Ranch Hand
Posts: 156
Hibernate Eclipse IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I heard that String concatenation like following takes more time for Compiler

String a="java";
String b="ranch"
String result=a+b;

why this + operator decreases performance?
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any time you use the '+' operator on Strings, you're creating a new object. Creating new objects is much slower than manipulating existing objects, so for that reason it is recommended to use a StringBuffer if you are performing multiple String concatenations in your code.

Using the append() method of StringBuffer, you do not create any new objects, but simply fill out spaces in an already-existing array.

There is mountains of info about this on the web, check out Google
    Bookmark Topic Watch Topic
  • New Topic