String (@NotNull String text) { text = text.trim(); final StringBuilder result = new StringBuilder(); boolean white = false; for (int i = 0, length = text.length(); i < length; i++) { final char c = text.charAt(i); if (StringUtil.isWhiteSpace(c)) { if (!white) { result.append(' '); white = true; } } else { white = false; result.append(c); } } return result.toString(); }