String (String text, int maxLength) { if (text.length() < maxLength) return ""; List<String> words = StringUtil.split(text, " "); StringBuilder builder = new StringBuilder(); final int delimiterLength = 1; int wordsLength = 0; for (String word: words) { wordsLength += word.length() + delimiterLength; if (wordsLength >= maxLength) break; builder.append(word); builder.append(" "); } return builder.toString(); }