Java String Split by Length split(String message, int maxPages, int pageSize)

Here you can find the source of split(String message, int maxPages, int pageSize)

Description

Helper method to split a string by pages and page size

License

Apache License

Parameter

Parameter Description
message a parameter
maxPages a parameter
pageSize a parameter

Declaration

public static List<String> split(String message, int maxPages, int pageSize) 

Method Source Code

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

import java.util.ArrayList;

import java.util.List;

public class Main {
    /**// www  .  j  av  a  2 s  .c  o  m
     * Helper method to split a string by pages and page size
     * 
     * @param message
     * @param maxPages
     * @param pageSize
     * @return
     */
    public static List<String> split(String message, int maxPages, int pageSize) {
        List<String> result = new ArrayList<String>(maxPages);
        for (int page = 0; page < maxPages; page++) {
            int startIndex = page * pageSize;
            int endIndex = (page + 1) * pageSize;
            if (endIndex < message.length()) {
                result.add(message.substring(startIndex, endIndex));
            } else {
                result.add(message.substring(startIndex));
                break;
            }
        }
        return result;
    }
}

Related

  1. getSplitLines(String input, int maxLineLength)
  2. lineSplit(String text, int len)
  3. split(final String value, final int maxLength)
  4. splitArray(byte[] array, int len)
  5. splitByLength(String string, int len)
  6. splitByteArray(byte[] inByteArray, int length)
  7. splitByteArray(final byte[] data, final int packetLength)