1.將集合轉成String字符串
String s=""; for (int i = 0; i < numList.size(); i++) { if (s=="") { s=numList.get(i); }else { s=s+","+numList.get(i); } }
List<String> numList=new ArrayList<String>(); for(int i=1; i<10; i++){ numList.add(String.valueOf(i)); }
2.將數組轉成String字符串
String [] arr = {"abc", "123", "@#&"}; StringBuffer sb = new StringBuffer(); for(int i = 0; i < arr.length; i++){ sb. append(arr[i]); } String ns = sb.toString(); System.out.println(ns); }