Java 小片段

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

}

上一篇:流程控制之if判断


下一篇:炸掉你的城堡!(pygame獾兔大战)