Java String Split by Length splitString(String str, int length)

Here you can find the source of splitString(String str, int length)

Description

split String

License

Apache License

Declaration

public static List<String> splitString(String str, int length) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.util.ArrayList;
import java.util.List;

public class Main {

    public static List<String> splitString(String str, int length) {
        List<String> list = new ArrayList<String>();
        for (int i = 0; i < str.length(); i += length) {
            int endIndex = i + length;
            if (endIndex <= str.length()) {
                list.add(str.substring(i, i + length));
            } else {
                list.add(str.substring(i, str.length() - 1));
            }/*from w  w w  . j  a v  a2  s  .co m*/
        }
        return list;
    }
}

Related

  1. splitParams(String string, int max)
  2. splitPreserveAllTokens(String str, String separatorChars, int max)
  3. splitString(String orig, String delim, int max)
  4. splitString(String s, int maxSize)
  5. splitString(String str, int length)
  6. splitString(String string, int maxCharsPerLine)
  7. splitString(String stringToSplit, int maxLength)
  8. splitStringByLength(String input, int length)
  9. splitStringFixedLen(String data, int interval)