Java Array Split splitSentences(String[] sentence, int limitLength, String reg)

Here you can find the source of splitSentences(String[] sentence, int limitLength, String reg)

Description

split Sentences

License

Open Source License

Declaration

public static List<String> splitSentences(String[] sentence, int limitLength, String reg) 

Method Source Code

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

import java.util.ArrayList;
import java.util.Arrays;

import java.util.List;

public class Main {
    public static List<String> splitSentences(String[] sentence, int limitLength, String reg) {

        List<String> listNewSentence = new ArrayList<String>();

        for (int i = 0; i < sentence.length; i++) {

            String[] word = sentence[i].split(reg);

            if (word.length <= limitLength) {
                listNewSentence.add(sentence[i]);

            }/*www. j a v a  2  s. c  o m*/

            else {

                int resto = word.length % limitLength;
                int portion = word.length / limitLength;

                String[][] splitSentence = new String[portion][];

                for (int j = 0; j < word.length - 1; i = i + limitLength) {

                    splitSentence[i] = new String[limitLength];

                    for (int k = 0; k < limitLength; k++) {
                        splitSentence[i][j] = word[i + j];

                    }

                }

                // add the tie to the last one
                splitSentence[splitSentence.length - 1] = new String[limitLength + resto];

                for (int j = 0; j < limitLength + resto; j++) {
                    splitSentence[splitSentence.length - 1][j] = word[splitSentence.length - 1 + j];

                }

                for (int j = 0; j < splitSentence.length; j++) {

                    listNewSentence.addAll(Arrays.asList(splitSentence[i]));

                }

            } // for

        } // else

        return listNewSentence;

    }
}

Related

  1. splitByByteSequenceSeparator(String theString, byte[] separatorByteSequence)
  2. splitByteArray(byte[] array, int each)
  3. splitByteArray(byte[] inByteArray, int length)
  4. splitData(String[] sData, int numMaps)
  5. splitOrderByFirst(byte[] pattern, byte[] src, int offset)
  6. splitStringOnFields(String in, int[] cuts)
  7. splitWordsL(String s, boolean splitOnWs, char[] delimiters)
  8. unsplit(String[] array, String seperator)