Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-28-2007, 07:00 PM
Administrator
 
Join Date: Dec 2006
Posts: 649
JavaForums has disabled reputation
Performance Issues (String Concatenation)
String concatenation is a task that is overlooked by the programmers. In this post, I will write about the performance issues related to string concatenation.
Strings are immutable objects and to concatenate strings, java has to perform a lot of operations in the background. Consider the following code segment:
String a= "a"; String b= "b"; String str = a + b;

This is compiled to
String str = (new StringBuffer()).append(a).append(b).toString();

You can see that Java compiler has to do a lot while concatenating strings. If you know that you might need to append or concatenate strings with you string, then you should use StringBuffer.
StringBuffer str = new StringBuffer(); str.append(a);

Let do a test in order to understand the performance difference. We will append a string 10000 times with a String object
and
10000 times with StringBuffer object
Lets see how much time it takes.
<div class="wp_syntax"><div class="code">String s = new String(); long start = System.currentTimeMillis(); for(int i=0;i
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Performance issues related to Look and Feel of GUI JavaForums Java Blogs 0 02-05-2008 02:01 PM
Java performance Issues (II) - Memory JavaForums Java Blogs 0 01-30-2008 03:01 PM
Java performance Issues (I) JavaForums Java Blogs 0 01-30-2008 03:01 PM
Database Column vs String Concatenation varun_33 Database 1 12-11-2007 06:14 PM
Performance Issues (StringTokenizer) JavaForums Java Blogs 0 11-29-2007 03:22 PM


All times are GMT +3. The time now is 12:38 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org