Here you can find the source of splitStringPerWord(String string, int wordsPerLine)
public static List<String> splitStringPerWord(String string, int wordsPerLine)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.List; public class Main { public static List<String> splitStringPerWord(String string, int wordsPerLine) { String[] words = string.split(" "); List<String> lines = new ArrayList<String>(); for (int lineCount = 0; lineCount < Math.ceil((float) words.length / (float) wordsPerLine); lineCount++) { String stringInLine = ""; for (int i = lineCount * wordsPerLine; i < Math.min(wordsPerLine + lineCount * wordsPerLine, words.length); i++) { stringInLine += words[i] + " "; }/*from w ww .j a va 2 s. c o m*/ lines.add(stringInLine.trim()); } return lines; } }