String (@NotNull String text, @NotNull String tokenizerDelimiters, boolean allWords, boolean leaveOriginalDelimiters) { StringTokenizer tokenizer = new StringTokenizer(text, tokenizerDelimiters, leaveOriginalDelimiters); StringBuilder out = new StringBuilder(text.length()); boolean toCapitalize = true; while (tokenizer.hasMoreTokens()) { String word = tokenizer.nextToken(); if (!leaveOriginalDelimiters && out.length() > 0) { out.append(' '); } out.append(toCapitalize ? capitalize(word) : word); if (!allWords) { toCapitalize = false; } } return out.toString(); }