Here you can find the source of wordWrap(String entry)
public static List<String> wordWrap(String entry)
//package com.java2s; //License from project: LGPL import java.util.ArrayList; import java.util.List; public class Main { public static List<String> wordWrap(String entry) { int ind = 0; List<String> out = new ArrayList<>(); while (ind <= entry.length()) { int nind = ind + 40; if (nind < entry.length()) { if (entry.charAt(nind) != ' ') { while (entry.charAt(nind) != ' ' && nind != 0) { nind--;/*from w w w. j ava 2 s .co m*/ } if (nind == 0) { nind = ind + 40; } } out.add(entry.substring(ind, nind)); ind = nind + 1; } else { out.add(entry.substring(ind)); break; } } return out; } }