Java Utililty Methods String Split by Length

List of utility methods to do String Split by Length

Description

The list of methods to do String Split by Length are organized into topic(s).

Method

ListsplitEqually(String _text, int _len)
Splits a Text to equal parts.
if (_text == null) {
    return null;
List<String> ret = new ArrayList<String>((_text.length() + _len - 1) / _len);
for (int start = 0; start < _text.length(); start += _len) {
    ret.add(_text.substring(start, Math.min(_text.length(), start + _len)));
return ret;
...
ListsplitEscapedString(String str, char sep, char esc, int maxPart)
split Escaped String
List<String> res = new ArrayList<>();
if (maxPart == 1) {
    res.add(str);
    return res;
int ptr = 0;
int beg = 0;
int len = str.length();
...
ListsplitFilenames(String text)
Get the list of JAR files from text field.
List<String> filenameList = new ArrayList<String>();
if (text != null && 0 < text.length()) {
    text = text.trim();
    String[] tmp = text.split(JAR_SEPARATOR);
    for (String s : tmp) {
        filenameList.add(s.trim());
return filenameList;
ListsplitHtmlString(String stringToSplit, int maxLength)
Split a line of text in lines no longer than maxLength characters.
List<String> lines = new ArrayList<String>();
boolean processingHtmlTag = false;
StringBuilder word = new StringBuilder();
StringBuilder line = new StringBuilder();
for (int index = 0; index < stringToSplit.length(); index++) {
    char character = stringToSplit.charAt(index);
    if (processingHtmlTag) {
        word.append(character);
...
String[]splitIntoFrames(String src, int maxFrameSize)
split Into Frames
if (src.length() <= maxFrameSize) {
    return new String[] { src };
} else {
    ArrayList<String> segs = new ArrayList<>();
    for (int i = 0; i < src.length(); i += maxFrameSize) {
        int end = Math.min(i + maxFrameSize, src.length());
        String seg = src.substring(i, end);
        segs.add(seg);
...
StringsplitIntoLine(String input, int maxCharInLine)
split Into Line
StringTokenizer tok = new StringTokenizer(input, " ");
StringBuilder output = new StringBuilder(input.length());
int lineLen = 0;
while (tok.hasMoreTokens()) {
    String word = tok.nextToken();
    while (word.length() > maxCharInLine) {
        output.append(word.substring(0, maxCharInLine - lineLen) + "\n");
        word = word.substring(maxCharInLine - lineLen);
...
ListsplitLines(String paragraph, int lineLength)
split Lines
List<String> lines = new ArrayList<String>();
int lineStart = 0;
int lastSpace = -1;
while (true) {
    int nextSpace = paragraph.indexOf(' ', lastSpace + 1);
    if (nextSpace == -1) {
        lines.add(paragraph.substring(lineStart, paragraph.length()));
        break;
...
String[]splitParams(String string, int max)
split Params
String[] words = string.trim().split(" ");
if (words.length <= 1) {
    return words;
ArrayList<String> list = new ArrayList<String>();
char quote = ' ';
String building = "";
for (String word : words) {
...
String[]splitPreserveAllTokens(String str, String separatorChars, int max)

Splits the provided text into an array with a maximum length, separators specified, preserving all tokens, including empty tokens created by adjacent separators.

The separator is not included in the returned String array.

return splitWorker(str, separatorChars, max, true);
String[]splitString(String orig, String delim, int max)
split String
List<String> out = new ArrayList<String>();
while (true) {
    if (out.size() == max - 1) {
        break;
    int n = orig.indexOf(delim);
    if (n < 0) {
        break;
...