stringbuffer-demand, given an array, int [] arr = {44,33,55,66,88} becomes [44, 33, 55, 66, 88]

Source: Internet
Author: User

Package CN. StringBuffer;/** * Demand, given an array, int [] arr = {44,33,55,66,88}; * becomes [a] .*/ Public classPinjie { Public Static voidMain (string[] args) {int[] arr = { -, -, -, the, the}; String Str=Pinjie (arr); System. out. println ("the string after stitching is:"+str); }     Public StaticString Pinjie (int[] arr) {StringBuffer buffer=NewStringBuffer (); Buffer.append ("[");  for(inti =0; i<arr.length;i++)        {            if(i = = arr.length-1) {buffer.append (arr[i]); }            Else{buffer.append (Arr[i]). Append (","). Append (" "); }} buffer.append ("]"); returnbuffer.tostring (); }}/** * Using StringBuffer to do splicing, and the use of string stitching is much more efficient, because stringbuffer is always a * and string is not the same, it will create a new string object each time, waste memory * * **/ 

stringbuffer-demand, given an array, int [] arr = {44,33,55,66,88} becomes [44, 33, 55, 66, 88]

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.