Java tutorial
//package com.java2s; import java.util.ArrayList; import java.util.List; public class Main { public static String breakLongLine(String longLine, int rowMaxLength) { List<String> shorterStrings = splitEqually(longLine, rowMaxLength); StringBuffer stringBuffer = new StringBuffer(); int renglones = shorterStrings.size() - 1; for (int i = 0; i < renglones; i++) { String shorterString = shorterStrings.get(i); stringBuffer.append(shorterString).append("\n"); } stringBuffer.append(shorterStrings.get(renglones)); return stringBuffer.toString(); } private static List<String> splitEqually(String text, int size) { List<String> ret = new ArrayList<String>((text.length() + size - 1) / size); for (int start = 0; start < text.length(); start += size) { ret.add(text.substring(start, Math.min(text.length(), start + size))); } return ret; } }