Comparison of String with StringBuffer

Source: Internet
Author: User

 Packagestring comparison;/** String compared to StringBuffer * string immutable, once assigned, cannot be modified * StringBuffer variable string. * Higher efficiency of StringBuffer*/ Public classTest8 { Public Static voidMain (string[] args) {//TODO auto-generated Method StubString str = "ABC"; Str.replace ("A", "B"); System.out.println (str);//ABCStringBuffer SBF =NewStringBuffer ("abc")); Sbf.replace (0, 1, "de"); System.out.println (SBF);//DEBCString S1= "Chinasofti"; intTime = 10000; @SuppressWarnings ("Unused") String TempStr= ""; LongStart1 =System.currenttimemillis ();  for(inti = 0; I < time; i++) {TempStr+=S1; }        LongEnd1 =System.currenttimemillis (); System.out.println ("String:" + (END1-START1) + "MS");//876msStringBuffer TEMPSBF=NewStringBuffer (); LongStart2 =System.currenttimemillis ();  for(inti = 0; I < time; i++) {tempsbf.append (S1); }        LongEnd2 =System.currenttimemillis (); System.out.println ("StringBuffer:" + (END2-START2) + "MS");//1ms    }}

Comparison of String with StringBuffer

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.