Java String Split by Line splitStringPerWord(String string, int wordsPerLine)

Here you can find the source of splitStringPerWord(String string, int wordsPerLine)

Description

split String Per Word

License

Open Source License

Declaration

public static List<String> splitStringPerWord(String string, int wordsPerLine) 

Method Source Code

//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;
    }
}

Related

  1. splitLogLine(final String logLine)
  2. splitMultiline(String text, boolean trimLines)
  3. splitNewLines(final String input)
  4. splitNextWord(String line)
  5. splitString(String line)
  6. splitter(String line, char delimeter)
  7. splitToLines(CharSequence str)
  8. splitToLines(final String str)
  9. splitToPairs(String Line)