string
转list
,分段截取
比如传入rubenrubenruben
和5,得到的list
就是{"ruben","ruben","ruben"}
这样的
|------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| hljs java /** * @param initial 初始字符串 * @param interval 分段长度 * @return */ public static List<String> stringSplit(String initial, Integer interval) { List<String> result = new LinkedList<>(); StringBuilder tmp = new StringBuilder(initial); int length = tmp.length(); while (length > 0) { if (interval > length) { interval = length; } String tmpStr = tmp.substring(0, interval); result.add(tmpStr); tmp.replace(0, interval, ""); length = tmp.length(); } return result; }
|