写一个java方法,循环对一个长字符串截取 ,每次截取500字符
时间: 2023-03-14 14:40:15 浏览: 139
java 一个截取字符串的函数
public static List<String> splitStringByLength(String str, int length) {
List<String> list = new ArrayList<String>();
int startIndex = 0;
while (startIndex < str.length()) {
int endIndex = startIndex + length;
if (endIndex > str.length()) {
endIndex = str.length();
}
list.add(str.substring(startIndex, endIndex));
startIndex = endIndex;
}
return list;
}
阅读全文