需求分析
优化接口时,需要手动拼接sql去调取神策的接口获取数据。好比将List<String> = {"123","456"}集合转化为('123','456')。
1 public class test3 { 2 3 public static void main(String[] args) { 4 String s = convertListToString(Arrays.asList("123", "456")); 5 System.out.println("转化后:" + "(" + s + ")"); 6 } 7 8 /** 9 * 需求分析:优化接口时,需要手动拼接sql去调取神策的接口获取数据 10 * 将List<String> = {"123","456"}集合转化为('123','456') 11 */ 12 public static String convertListToString(List<String> strlist) { 13 StringBuilder sb = new StringBuilder(); 14 if (!CollectionUtils.isEmpty(strlist)) { 15 for (int i = 0; i < strlist.size(); i++) { 16 if (i == 0) { 17 sb.append("'").append(strlist.get(i)).append("'"); 18 } else { 19 sb.append(",").append("'").append(strlist.get(i)).append("'"); 20 } 21 } 22 } 23 return sb.toString(); 24 } 25 26 }View Code
运行结果
标签:String,456,123,集合,sb,strlist,append From: https://www.cnblogs.com/liaowenhui/p/16720702.html