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]