Here you can find the source of format(final String s, final int width, final int intend)
public static String format(final String s, final int width, final int intend)
//package com.java2s; //License from project: Open Source License import java.util.Arrays; public class Main { public static String format(final String s, final int width, final int intend) { final String ws = ws(intend); if (s.length() < width - intend) return ws + s; final StringBuilder buf = new StringBuilder(); int pos = 0; while (pos + width - intend < s.length()) { buf.append(ws).append(s.substring(pos, pos + width - intend)).append("\n"); pos += width - intend;/*from w w w .j a va2 s. c om*/ int indexOfS = s.indexOf(' ', pos); while (indexOfS == pos) { pos++; indexOfS = s.indexOf(' ', pos); } } buf.append(ws).append(s.substring(pos)); return buf.toString(); } public static String ws(final int length) { return repeat(' ', length); } public static String repeat(final char c, final int count) { if (count <= 0) return ""; final char[] a = new char[count]; Arrays.fill(a, c); return new String(a); } }