java实现将一个字符串集合,如果集合长度大于900,将集合元素每900个通过逗号拼接为一个字符串,插入进String类型的List中,如果不大于,将所有的元素通过逗号拼接为一个字符串,插入String类型的List中返回
时间: 2023-05-26 18:02:06 浏览: 104
MySQL拼接字符串函数GROUP_CONCAT详解
```java
public static List<String> splitString(List<String> inputList) {
List<String> resultList = new ArrayList<>();
StringBuilder stringBuilder = new StringBuilder();
int size = inputList.size();
if (size > 0) {
if (size > 900) {
for (int i = 0; i < size; i++) {
stringBuilder.append(inputList.get(i));
if ((i + 1) % 900 == 0) {
resultList.add(stringBuilder.toString());
stringBuilder = new StringBuilder();
} else {
stringBuilder.append(",");
}
}
if (stringBuilder.length() > 0) {
resultList.add(stringBuilder.toString());
}
} else {
for (int i = 0; i < size; i++) {
stringBuilder.append(inputList.get(i)).append(",");
}
if (stringBuilder.length() > 0) {
stringBuilder.deleteCharAt(stringBuilder.length() - 1);
}
resultList.add(stringBuilder.toString());
}
}
return resultList;
}
```
阅读全文