Here you can find the source of splitLine(String input, int splitPosition)
public static List<String> splitLine(String input, int splitPosition)
//package com.java2s; // SOLUTIONS CORP. OR ITS LICENSORS. import java.util.ArrayList; import java.util.List; public class Main { public static List<String> splitLine(String input, int splitPosition) { List<String> lines = new ArrayList<String>(); StringBuilder stringBuilder = new StringBuilder(input.trim()); boolean linesRemaining = true; while (linesRemaining) { if (stringBuilder.length() <= splitPosition || stringBuilder.lastIndexOf(" ") < splitPosition) { lines.add(stringBuilder.toString()); linesRemaining = false;// www. j a v a 2s .c om } else { int indexOfSpace = stringBuilder .indexOf(" ", splitPosition); String nextLine = stringBuilder.substring(0, indexOfSpace + 1); lines.add(nextLine); stringBuilder.delete(0, indexOfSpace + 1); } } return lines; } /** * Trim the leading and trailing whitespace from a string. If a null * reference is passed in then return an empty string. */ public static String trim(String string) { if (string == null) { return ""; } return string.trim(); } }