Java 小片段

时间:2022-06-23 02:32:40

public static String listToString(List<String> stringList){

if (stringList==null) {

return null;

}

StringBuilder result=new StringBuilder();

result.append("(");

boolean flag=false;

for (String string : stringList) {

if (flag) {

result.append(",");

}else {

flag=true;

}

result.append("'");

result.append(string);

result.append("'");

}

result.append(")");

return result.toString();

}

public static void main(String[] args) {

List<String> list=new ArrayList<String>();

list.add("aaa");

list.add("bbb");

list.add("ccc");

System.out.println(listToString(list));//aaa,bbb,ccc

}