Skip to main content

Posts

Showing posts with the label StringBuilder

String manipulation in Java

One topic most of the developers in early days of their career overlook while programming is STRING MANIPULATION . This article will throw some light on this topic, so that one can make habit of some efficient coding. I am going to give some insight into Java string manipulation and some better ways to do string manipulation. In Java String objects are immutable, what it means is once you create a String object in Java, it can not be changed/modified. For example look at the following code. String a = "A String Object"; a = "Second String Object"; In the above code, we created a String object 'a' at line#1 with the value "A String Object", and in line#2 we tried to change the value of the object 'a' to "Second String Object". As I mentioned little earlier, when you create a String object in Java, it can not be changed. In line#2 when you try to change the value of object 'a', JVM [Java Virtual Machine] will c...