Java performance of StringBuilder append chains

Posted by ultimate_guy on Programmers See other posts from Programmers or by ultimate_guy
Published on 2012-11-02T15:42:27Z Indexed on 2012/11/02 17:28 UTC
Read the original article Hit count: 504

Filed under:
|

In Java, if I am building a significant number of strings, is there any difference in performance in the following two examples?

StringBuilder sb = new StringBuilder();

for (int i = 0; i < largeNumber; i++) {
    sb.append(var[i]);
    sb.append('=');
    sb.append(value[i]);
    sb.append(',');
}

or

StringBuilder sb = new StringBuilder();

for (int i = 0; i < largeNumber; i++) {
    sb.append(var[i]).append('=').append(value[i]).append(',');
}

Thanks!

© Programmers or respective owner

Related posts about java

Related posts about Performance