Java String Split by Length strSplit(String src, int firstLineLength, int otherLineLength)

Here you can find the source of strSplit(String src, int firstLineLength, int otherLineLength)

Description

str Split

License

Open Source License

Declaration

private static List<String> strSplit(String src, int firstLineLength, int otherLineLength) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.*;
import java.util.List;

public class Main {
    private static List<String> strSplit(String src, int firstLineLength, int otherLineLength) {
        List<String> result = new ArrayList<>();
        String subStr = null;//from   ww  w  .  j  ava 2  s . c  o m
        if (firstLineLength < src.length()) {
            subStr = src.substring(0, firstLineLength);
            result.add(subStr);
            for (int i = firstLineLength; i < src.length(); i += otherLineLength) {
                if (i + otherLineLength > src.length()) {
                    subStr = src.substring(i, src.length());
                } else {
                    subStr = src.substring(i, i + otherLineLength);
                }
                result.add(subStr);
            }
        } else {
            subStr = src.substring(0, src.length());
            result.add(subStr);
        }

        return result;
    }
}

Related

  1. splitString(String string, int maxCharsPerLine)
  2. splitString(String stringToSplit, int maxLength)
  3. splitStringByLength(String input, int length)
  4. splitStringFixedLen(String data, int interval)
  5. splitWorker(final String str, final String separatorChars, final int max, final boolean preserveAllTokens)