Posts

Showing posts with the label string

Optimised Way of Modifying a String in Java

It probably rarely occurs to people there could be a small bump on performance when manipulating strings in Java, since the computing power nowadays also considered to be infinite, and nobody will really try to add a dozen dead sea scrolls into one string or tweak it. Why should I bother!? Yes, when it comes to critical systems, or simply for optimisation's sake, devs should be more conscious about what object to use when altering a string. As a starter, String  is the most straight forward object to use in Java. The good thing about string object is that it is an immutable object , which means it will NOT change after it is instantiated, and any modification will cause a copy of the object be created. There is a lot of benefits to this implementation like  those . But when it comes down to mass modifications, it is more of a pain in the jacksie. What happens now, panic? Of course not, the clever people before us have not only come across the problem b...