Java five-way String concatenation

Source: Internet
Author: User
Package test; import Org. apache. commons. lang. stringutils; public class cutstring {// worst performing public string testplus () {string S = ""; for (INT I = 0; I <10000; I ++) {S = S + String. valueof (I) ;}return s ;}// Public String testconcat () {string S = ""; for (INT I = 0; I <10000; I ++) {S = S. concat (string. valueof (I);} return s;} // The performance is almost the same as teststringbuffer, which is better than public string testjoin () {string [] list = new string [10000]; for (INT I = 0; I <10000; I ++) {list [I] = string. valueof (I);} return stringutils. join (list, "");} Public String teststringbuffer () {stringbuffer sb = new stringbuffer (); long L1 = system. currenttimemillis (); For (INT I = 0; I <10000; I ++) {sb. append (string. valueof (I);} Long L2 = system. currenttimemillis (); system. out. println (l2-l1); return sb. tostring () ;}// method with the highest performance public void teststringbuilder () {stringbuilder sb = new stringbuilder (); For (INT I = 0; I <100000; I ++) {sb. append (string. valueof (I);} sb. tostring ();} public static void main (string [] ARGs) {system. out. println (New cutstring (). teststringbuffer ());}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.