Here you can find the source of splitSentences(String[] sentence, int limitLength, String reg)
public static List<String> splitSentences(String[] sentence, int limitLength, String reg)
//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; } }