Java Utililty Methods Word Wrap

List of utility methods to do Word Wrap

Description

The list of methods to do Word Wrap are organized into topic(s).

Method

StringwordWrap(String input, int width, Locale locale)
Reformats a string where lines that are longer than width are split apart at the earliest wordbreak or at maxLength, whichever is sooner.
if (input == null) {
    return "";
} else if (width < 5) {
    return input;
} else if (width >= input.length()) {
    return input;
StringBuffer buf = new StringBuffer(input);
...
StringwordWrap(String input, int width, Locale locale)
Reformats a string where lines that are longer than width are split apart at the earliest wordbreak or at maxLength, whichever is sooner.
if (input == null) {
    return "";
} else if (width < 5) {
    return input;
} else if (width >= input.length()) {
    return input;
if (locale == null) {
...
StringwordWrap(String input, int width, Locale locale)
word Wrap
if (input == null) {
    return "";
} else if (width < 5) {
    return input;
} else if (width >= input.length()) {
    return input;
StringBuilder buf = new StringBuilder(input);
...
StringwrapString(String original, int width, BreakIterator breakIterator, boolean removeNewLines)
Wrap multi-line strings.
String[] sarray = wrapStringToArray(original, width, breakIterator, removeNewLines);
StringBuffer retBuf = new StringBuffer();
for (int i = 0; i < sarray.length; i++) {
    retBuf.append(sarray[i]);
    retBuf.append('\n');
return retBuf.toString();
String[]wrapStringToArray(String original, int width, BreakIterator breakIterator, boolean removeNewLines)
Wrap multi-line strings (and get the individual lines).
if (original.length() == 0) {
    return new String[] { original };
String[] workingSet;
if (removeNewLines) {
    original = trimString(original);
    original = original.replace('\n', ' ');
    workingSet = new String[] { original };
...
StringwrapText(String s, int width, boolean noIterator)
wrap Text
if (noIterator) {
    if (s == null || s.length() <= width) {
        return s;
    String ret = "";
    int start = 0;
    int end = width;
    int len = s.length();
...
StringwrapText(String string, int theWrapLength)
wrap Text
return wrapText(string, "\n", theWrapLength);