Problem with String in Java
by, 04-26-2012 at 06:28 PM (377 Views)
In java string, biggest strength well known as immutability is actually the biggest problem encountered in case it is not used appropriately. String is created many times and lots of operations are being performed at them. For example, string conversion into lowercase, uppercase, concatenating with string or getting substring out. Though String is considered as immutable class, when a new string is created evertime and the old one gets discarded that makes temporary garbage a lot, in heap. If String literal is used to create the String and they are present in the String pool. For such problem resolution, two classes are provided by Java which are StringBuilder and StringBuffer. StringBuilder is new one & StringBuffer is older one, added in JDK 5.