Posts

Showing posts from October 10, 2007

Manipulating String intelligently

Image
Performance and Optimizations are the key features desired in Java Programming. So here are some examples, how to make improvement in your String manipulation..



String is the most encountered Objects in Java Programming. Till Tiger, we have 3 Classes to manipulate Strings. These are String, StringBuilder, StringBuffer.

String is immutable whereas StringBuffer and StringBuilder can change their values.

StringBuilder was introduced in J2SE5 or Tiger.The only difference between StringBuffer and StringBuilder is that StringBuilder is unsynchronized whereas StringBuffer is synchronized. So when the application needs to be run only in a single thread then it is better to use StringBuilder. StringBuilder is more efficient than StringBuffer.

Here are some examples given by Mr. Heinz Kabutz about how to perform String Manipulation intelligently.

We start with a basic concatenation based on +=:

public static String concat1(String s1, String s2, String s3,
String s4, St…