StringBuilder (@NotNull String text) { if (text.isEmpty()) { return null; } final StringBuilder buf = new StringBuilder(text.length()); for (int i = 0, length = text.length(); i < length; i++) { char c = text.charAt(i); if (c <= ' ' || Character.isSpaceChar(c)) { if (buf.length() == 0 || buf.charAt(buf.length() - 1) != ' ') { buf.append(' '); } } else { buf.append(c); } } return buf; }