When using string, we should pay attention to the problem: Try not to do string concatenation operations frequently. Because once the string is created immutable, as long as it is frequently spliced, a large number of string objects are created in the string constant pool, causing problems with garbage collection.
Public class stringtest04{ public static void main ( String[] args) { string[] ins={"Sport", "music", "food" , "Sleep"}; //asked to stitch the above interest into a string "Sport,music,food,sleep" string temp= ""; for (int i=0;i<ins.length;i++) { if (i==i.length-1) { temp += ins[i]; }else{ temp += ins[i]+ ","; } &nBSP;} &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;SYSTEM.OUT.PRINTLN (TMP); }}
This article is from the "Gaogaozi" blog, make sure to keep this source http://hangtiangazi.blog.51cto.com/8584103/1662476
Issues to be aware of when using string