51工具盒子

依楼听风雨
笑看云卷云舒,淡观潮起潮落

java巨大字符串截取

stringlist,分段截取

比如传入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; } |

赞(0)
未经允许不得转载:工具盒子 » java巨大字符串截取