Java Application Performance Tuning using String Builders

source: https://www.educba.com/string-vs-stringbuilder/
String greeting = “Hi”;greeting = greeting + “,” + “Happy Birthday” + “,” + “ Alex” + “!!”;
StringBuilder greeting = new StringBuilder("Hi");greeting = greeting.append(“,”).append(“Happy Birthday”).append(“,”).append(“ Alex”).append(“!!”);
  • Use String — If a string is going to remain constant throughout the program.
  • Use String Builder — If a string can manipulate(change) a lot during the program execution and will only be accessed from a single thread.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Anuradha Karunarathna

Anuradha Karunarathna

Senior Software Engineer@ WSO2 | Computer Science and Engineering graduate@ University of Moratuwa, SriLanka