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());
 }

}

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Pin It on Pinterest

Share This

Share this post with your friends!

Share This

Share this post with your friends!