日期:2014-05-20 浏览次数:21036 次
package com.revise.text;
import java.util.ArrayList;
public class ToString {
private ArrayList<String> StringList = null;
private StringBuilder tempString = null;
public ToString(){
StringList = new ArrayList<String>();
tempString = new StringBuilder();
}
public void AddString(String value){
StringList.add(value);
}
public String getValue(){
tempString.append("{");
for(String temp : StringList){
tempString.append("\"").append(temp).append("\",");
}
String temp_1 = tempString.toString();
temp_1 = (String) temp_1.substring(0, temp_1.length() -1);
temp_1 = temp_1 + "}";
return temp_1;
}
public static void main(String[] args) {
ToString toSting = new ToString();
toSting.AddString("aaa");
toSting.AddString("bbb");
System.out.println(toSting.getValue());
}
}
List<String> list = new ArrayList<String>();
list.add("aaa");
list.add("bbb");
list.add("ccc");
String[] array = list.toArray(new String[list.size()]);
用stringbuffer类也可以
最终结果是类似这样 {“aaa”,"bbb","ccc"}
String str1 = "aaa";
String str2 = "bbb";
String str3 = "ccc";
List<String> list = new ArrayList<String>();