StringBuilder class in Java 5.0

java.lang.StringBuilder

StringBuilder class is introduced in Java 5.0 version. This class is replacement for the
existing StringBuffer class. If you look into the operations of the both the classes,
there is no difference.

also read:

  • If you are using StringBuilder, no guarantee of synchronization. This is the only difference with StringBuffer class.
  • It is recommended that this class be used in preference to StringBuffer as it will be faster.
  • You can easily replace the exisitng StringBuffer implementaion with StringBuilder without any compilation
    problem.

StringBuilderExample.java

package javabeat.net.java;

/**
 * source : www.javabeat.net
 */
public class StringBuilderExample {
 public static void main(String[] args) {
 StringBuilder stringBuilder = new StringBuilder();
 stringBuilder.append("Add a string");
 System.out.println(stringBuilder.toString());
 }

}

Comments

comments

About Krishna Srinivasan

He is Founder and Chief Editor of JavaBeat. He has more than 8+ years of experience on developing Web applications. He writes about Spring, DOJO, JSF, Hibernate and many other emerging technologies in this blog.

Trackbacks

  1. […] without even iterating the whole list . As a side note, we could also use a StringBuffer (Read : StringBuilder) to concatenate our Strings, but the return should be stringbuffer.toString (). The example below […]

Speak Your Mind

*

Close
Please support the site
By clicking any of these buttons you help our site to get better