List<String> data = new ArrayList<>();
data.add("11");
data.add("22");
data.add("33");
String result = data.toString();
System.out.println("字符串结果:"+result);
StringBuilder sb = new StringBuilder();
for (String element : data) {
sb.append(element).append(", ");
}
if (!data.isEmpty()) {
sb.setLength(sb.length() - 2); // 移除最后的逗号和空格
}
String result2 = sb.toString();
System.out.println("转换结果:"+result2);
//阿里转换
String s = JSONObject.toJSONString(data);
System.out.println("阿里转:"+s);
打印结果如下所示:
字符串结果:[11, 22, 33]
转换结果:11, 22, 33
阿里转:["11","22","33"]