不废话,直接上代码.
/**
* 把String按一定长度拆分,返回ListString
*
* @param str
* @param len
* @return
*/
public List<String> getListStr(String str, int len) {
List<String> listStr = new ArrayList<>();
int strLen = str.length();
int start = 0;
int num = len;
String temp = null;
while (true) {
try {
if (num >= strLen) {
temp = str.substring(start, strLen);
} else {
temp = str.substring(start, num);
}
} catch (Exception e) {
LogUtils.i("拆分完毕", "");
break;
}
listStr.add(temp);
start = num;
num = num + len;
}
return listStr;
}
网友评论