StringBuffer Based on JAVA

Source: Internet
Author: User
Tags string methods

Summary: 1. StringBuffer is a thread-safe variable String sequence. 2. Although String has a variety of String methods, if you frequently increase or decrease String sequences, we recommend that you use StringBuffer first. [Java] package com. cxy. e; public class E {public static void main (String [] args) {/** String + operations are actually created StringBuffer objects, then use the append method to change * so the efficiency of directly using StringBuffer for string change operations is higher than that of String * Another important operation of StringBuffer and StringBuffer will modify the current string.. **/StringBuffer sb = new StringBuffer (); sb. append ("java "). append ("api"); System. out. println (sb. toString (); System. out. println ("=================="); // insert sb. insert (5, "6.0"); System. out. println (sb. toString (); System. out. println ("=================="); // replace www.2cto.com sb. replace (5, 8, "7.0"); System. out. println (sb. toString (); System. out. println ("===================="); // Output System in reverse order. out. println (sb. reverse (); System. out. println ("===================="); // delete a location sb. reverse (); System. out. println (sb. delete (5, 9); System. out. println ("========================= ");}}

Related Article

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.